Remove duplicate links using .htaccess
I know there are a few answers reagrding this topic, however i need something more :)
- I need all my www pages to redirect to non-www
- I need all my index.php to be removed
- I need .php to be removed from all the pages (site.com/sss.php to site.com/sss)
- Is there a difference between http://site.com/sss/ and http://site.com/sss (the slash) 开发者_如何学编程?
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# 1. www.example.com -> example.com
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
# 2. index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteCond %{THE_REQUEST} !^POST
RewriteRule ^index\.php$ http://example.com/ [R=301,L]
# 3. remove trailing slashes if it's not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\example\.com$ [NC]
RewriteRule ^(.+)/$ http://example.com/$1 [R=301,L]
# 3. remove .php extension from files
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://example.com/$1 [R=301,L]
# 3. internally rewrite to .php if a file exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.+) /$1.php [L]
</IfModule>
4.Yes, the added slash means that the resource is a directory, whereas the absence of the slash means the resource is a file without an extension.
精彩评论