.htaccess使用尾部斜杠重定向到url

时间:2015-06-13 21:32:06

标签: .htaccess mod-rewrite redirect

请帮我修改.htaccess中的重定向。我需要重定向到带有斜杠的网址

www.example.cz/about - > www.example.cz/about/
www.example.cz/index.php?path=about - > www.example.cz/about /

和最后一个 www.example.cz/index.php - > www.example.cz

#MY .htaccess
<FilesMatch "\.phtml$">
  Order Deny,Allow
  Deny From All
</FilesMatch>

ErrorDocument 404 /404/

RewriteEngine On 
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.cz$
RewriteRule (.*) http://www.example.cz/$1 [R=301,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

1 个答案:

答案 0 :(得分:0)

我解决了尾随斜杠和index.php重复的问题:

<FilesMatch "\.phtml$">
  Order Deny,Allow
  Deny From All
</FilesMatch>

ErrorDocument 404 /404/

RewriteEngine On 
RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.cz$
RewriteRule (.*) http://www.example.cz/$1 [R=301,L]
RewriteRule ^index.php$ http://example.cz/$1 [R=301,L]    

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /?path=$1 [L,QSA]

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

现在.htaccess正在做

www.example.cz/index.php --> www.example.cz/
www.example.cz/about--> www.example.cz/about/
example.cz --> www.example.cz

接下来,我需要解决

www.example.cz/?path=about--> www.example.cz/about/
www.example.cz/about/ --> wwww.example.cz
相关问题