Hi everyone,
I have a few questions regarding .htaccess files and they are as follows:
1. I am very new to .htaccess and wrote one for my website by copying and pasting from all over the web so i was wondering if someone here could advise me on the correct order i should place my rules.
Here is my .htaccess...
AddDefaultCharset utf-8
Options +FollowSymLinks
RewriteEngine On
# Remove trailing slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301]
# Redirect index to root
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
# Block attack
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
# Canonical remove www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http:
//%1%{REQUEST_URI} [R=301,QSA,NC,L]
# Keep domain on top
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteCond %{HTTP_HOST} !^static.example.com$ [NC]
RewriteCond %{HTTP_HOST} !^m.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
# Remove php extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
ErrorDocument 403 /403.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 500 /500.shtml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/javascript
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
2. Is there anything important that i am missing in the htaccess file or if there is any changes / recommendations you may have?
3. I have a slight problem with trailing slash's everything is fine but when it comes to main home/index page it does not seem to work.
Example:
example.com////
Will not rewrite/redirect to
example.com
All other pages work fine with this rule.
I thank you for your help/comments if you are nice enough to leave one :)
Regards Shaun.
[edited by: phranque at 1:53 pm (utc) on Feb 18, 2014]
[edit reason] unlinked url [/edit]