尝试为每个链接添加尾部斜杠。即http://mysite.com/products应该使 301 重定向到 http://mysite.com/products/等等,但是如何呢?这是 htaccess:
RewriteEngine on
DirectoryIndex index.php
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_URI} \.css$
RewriteCond %{QUERY_STRING} ^pack$
RewriteRule ^(.*)$ /modules/system/css_compactor.php?filename=$1 [L]
RewriteCond %{REQUEST_URI} \.js$
RewriteCond %{QUERY_STRING} ^pack$
RewriteRule ^(.*)$ /modules/system/js_compactor.php?filename=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
RewriteRule /admin/(.*)$ /admin/index.php
需要帮助!
最佳答案
这是我正在使用的
RewriteEngine on
RewriteBase /
### CHECK FOR TRAILING SLASH - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
基本上,这可以确保它不会向文件添加尾随,而仅向文件夹或路径添加尾随。
编辑
使其独立于域
RewriteRule ^(.*)$ $1/ [L,R=301]
关于.htaccess - 重定向到尾部斜杠 (htaccess),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7267755/