.htaccess

 

enable mod_rewrite (jako první řádek):  Options +FollowSymLinks

Redirecting a non-www URL to a www URL

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^abc\.net$
RewriteRule (.*) http://www.abc.net/$1 [R=301,L]

Redirecting entire website to https

RewriteEngine ON RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

 

A custom redirection example

redirect url ‘http://www.abc.net?p=100&q=20 ‘ to ‘http://www.abc.net/10020pq’

RewriteEngine ON RewriteRule ^http://www.abc.net/([0-9]+)([0-9]+)pq$ ^http://www.abc.net?p=$1&q=$2

Prevent Image Hotlinking for your Website

RewriteEngine ON RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERERER} !^http://(www\.)?mydomain.com/.*$ [NC] RewriteRule \.(gif|jpeg|png)$ - [F].

Redirect Users to Maintenance Page

RewriteCond %{REQUEST_URI} !^/admin/ [NC] RewriteCond %{REQUEST_URI} !^((.*).css|(.*).js|(.*).png|(.*).jpg) [NC] RewriteRule ^(.*)$ /ErrorDocs/Maintainence_Page.html [NC,L,U,QSA]

Mapping IP Address to Domain Name

For Mapping L.M.N.O address to a domain name www.hellovisit.com RewriteCond %{HTTP_HOST} ^L\.M\.N\.O$ [NC] RewriteRule ^(.*)$ http://www.hellovisit.com/$1 [L,R=301]

FilesMatch Tag

<FilesMatch “\.(png|jpg)$”> Order Allow, Deny Deny from All </FilesMatch>

Error documents for different error codes:

ErrorDocument <error-code> <path-of-document/string-representing-html-file-content>

např.

ErrorDocument 404 /error-docs/error-404.html

Setting the Environment variables

SetEnv OWNER “Gunjit Khera”

Unsetting the Environment variables

UnsetEnv OWNER

Defining different MIME types for files

<IfModule mod_mime.c> AddType application/javascript js AddType application/x-font-ttf ttf ttc </IfModule>

How to Limit the size of Uploads and Downloads in Apache

php_value upload_max_filesize 20M php_value post_max_size 20M php_value max_execution_time 200 php_value max_input_time 200

Making Users to download .mp3 and other files before playing on your website

AddType application/octet-stream .mp3 .zip

Setting Directory Index for Website

DirectoryIndex index.html index.php yourpage.php

How to enable GZip compression for Files to save site’s bandwidth

<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE application/html AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript </IfModule>

Playing with the File types

RemoveHandler cgi-script .php .pl .py AddType text/plain .php .pl .py

Setting the Time Zone for Apache server

SetEnv TZ India/Kolkata

Přesměrování na www v http a https:

RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ %{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Autentizace

AuthType Basic AuthName "Password Required" AuthUserFile "/www/passwords/password.file" AuthGroupFile "/www/passwords/group.file" Require group admins

How to enable Cache Control on Website

<FilesMatch "\.(ico|png|jpeg|svg|ttf)$"> Header Set Cache-Control "max-age=3600, public" </FilesMatch> <FilesMatch "\.(js|css)$"> Header Set Cache-Control "public" Header Set Expires "Sat, 24 Jan 2015 16:00:00 GMT" </FilesMatch>

Configuring a single file, the <files> option

<files conf.html=""> Order allow, deny Deny from 188.100.100.0 </files>

Enabling CGI scripts to run outside of cgi-bin folder

AddHandler cgi-script .cgi Options +ExecCGI

How to enable SSI on Website with .htaccess

In case you want to enable it for .html files you need to add following lines:

AddHandler server-parsed .html After this following in the html file would lead to SSI.


How to Prevent website Directory Listing

Options -Indexes

Changing Default charset and language headers

AddDefaultCharset UTF-8 DefaultLanguage en-US

 
  • 0 Usuários acharam útil
Esta resposta lhe foi útil?

Artigos Relacionados

HTML - meta tagy

Meta tagy Meta tagy jsou zvláštní značky, které se píšou do hlavičky stránky. Popisek =...

PHP webhosting

Podporované verze aktuálně náš webhosting běží na verzi 7.4.29 verze 8.1 bude mít aktivní...