到处重写尾随斜杠

时间:2015-01-18 21:54:26

标签: .htaccess mod-rewrite

我的.htaccess文件出现问题 它看起来像这样:

RewriteEngine On  

RewriteCond %{HTTP_HOST} ^website\.de [NC]  
RewriteRule ^(.*)$ http://www.website.de/folder/$1 [L,R=301]  

RewriteRule ^traffic/?$ traffic.php [NC,L]  
RewriteRule ^what-if/?$ whatif.php [NC,L]  

如果我致电www.website.de/folder/traffic,我会www.website.de/folder/traffic/ 但是,如果我拨打www.website.de/folder/what-if,则会丢失尾随的/

如何在任何地方添加?

1 个答案:

答案 0 :(得分:0)

您必须指定RewriteBase,因为您的htaccess位于子文件夹中 此外,您必须禁用MultiViews选项以避免出现问题。

Options -MultiViews

RewriteEngine On
RewriteBase /folder/

RewriteCond %{HTTP_HOST} ^website\.de$ [NC]  
RewriteRule ^(.*)$ http://www.website.de/folder/$1 [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+)$ $1/ [R=301,L]

RewriteRule ^traffic/$ traffic.php [NC,L]  
RewriteRule ^what-if/$ whatif.php [NC,L]