重定向到尾随斜杠(htaccess) [英] Redirect to trailng slash (htaccess)
本文介绍了重定向到尾随斜杠(htaccess)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试将斜杠添加到每个链接。即 http://mysite.com/products 应该使301重定向到 http://mysite.com/products/ 等。但是如何?这是htaccess:
Trying to add trailing slash to every link. i.e. http://mysite.com/products should make 301 redirect to http://mysite.com/products/ etc. But how? Here is 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]
基本上,这可以确保不会添加尾随到文件,仅添加文件夹或路径。
Basically, this makes sure that it doesn't add a trailing to file and only folders or paths.
编辑
到使其独立于域
RewriteRule ^(.*)$ $1/ [L,R=301]
这篇关于重定向到尾随斜杠(htaccess)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文