我知道有一些答案重申这个话题,但我需要更多的东西:)
答案 0 :(得分:2)
<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.是的,添加的斜杠意味着资源是一个目录,而缺少斜杠意味着资源是没有扩展名的文件。