# Redirect to domain with www.
RewriteEngine on
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect to domain without www.
RewriteEngine on
# Redirect to domain without www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
Do not force www/no-www domain
RewriteEngine on
# Redirect to another domain: www.test.org.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)?test\.org$ [NC]
RewriteRule .* http://www.test.org%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(www\.)?test\.org$ [NC]
RewriteRule .* https://www.test.org%{REQUEST_URI} [R=301,L]
Trailing slash for URLs
RewriteEngine on
# Ensure all directory URLs have a trailing slash.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Same for HTTPS:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
301 Redirect Directories
#301 Redirect Entire Directory.
RedirectMatch 301 ^/old/(.*)$ /new/$1
# Block users by IP
order allow,deny
deny from 127.0.0.1
deny from 127.0.0.2
allow from all
Change Default Directory Pages
# Change default directory pages.
DirectoryIndex new
Prevent viewing of .htaccess
# Prevent viewing of htaccess file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
Change Default Directory Pages
# Change default directory pages.
DirectoryIndex new
Prevent viewing of htaccess file
# Prevent viewing of htaccess file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
Prevent Directory Listing
# Prevent directory listings
Options All -Indexes
Compression
# Compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Enable Symbolic Links
# Follow symbolic links.
Options +FollowSymLinks
RewriteEngine on
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect to domain without www.
RewriteEngine on
# Redirect to domain without www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
Do not force www/no-www domain
RewriteEngine on
# Redirect to another domain: www.test.org.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)?test\.org$ [NC]
RewriteRule .* http://www.test.org%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(www\.)?test\.org$ [NC]
RewriteRule .* https://www.test.org%{REQUEST_URI} [R=301,L]
Trailing slash for URLs
RewriteEngine on
# Ensure all directory URLs have a trailing slash.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Same for HTTPS:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
301 Redirect Directories
#301 Redirect Entire Directory.
RedirectMatch 301 ^/old/(.*)$ /new/$1
# Block users by IP
order allow,deny
deny from 127.0.0.1
deny from 127.0.0.2
allow from all
Change Default Directory Pages
# Change default directory pages.
DirectoryIndex new
Prevent viewing of .htaccess
# Prevent viewing of htaccess file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
Change Default Directory Pages
# Change default directory pages.
DirectoryIndex new
Prevent viewing of htaccess file
# Prevent viewing of htaccess file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
Prevent Directory Listing
# Prevent directory listings
Options All -Indexes
Compression
# Compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Enable Symbolic Links
# Follow symbolic links.
Options +FollowSymLinks