我需要始终重定向到/。 例如,如果我的网址为http://link.com/tag///////,则应将其重定向到http://link.com/tag//////(应删除所有斜杠,只留下一个)。怎么做?我正在使用CodeIgniter,我的.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} system|application
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
答案 0 :(得分:1)
尝试在RewriteBase /
下面添加此内容:
RewriteCond %{THE_REQUEST} \ /+([^\ \?]+?)/{2,}([^\ \?]*)
RewriteRule ^ /%1/%2 [L,R=301]
答案 1 :(得分:0)
将此规则置于顶部之前的其他规则:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)/{2,}[?\s] [NC]
RewriteRule ^ /%1/ [L,R=301]