2014-04-28 124 views
1

我使用這個的.htaccess這個裏面:.htacces沒有斜線重定向到具有斜線

DirectoryIndex index.php index.html 
DirectorySlash On 

Options -Indexes 

Options +FollowSymlinks 

RewriteEngine On 
RewriteBase/

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

RewriteCond %{REQUEST_URI} ^/(page1|page2|page3)$ 
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L] 

#Show every html,htm and xml as php 
RewriteRule ^(.*)\.html$ $1.php [nc] 
RewriteRule ^(.*)\.htm$ $1.php [nc] 
RewriteRule ^(.*)\.xml$ $1.php [nc] 

,但我沒有得到重定向到http://example.com/page1 - >http://example.com/page1/(和其他人第2頁第3頁和)。因爲我在本地測試我的網址將是 localhost/example/page1 並且應該重定向到 localhost/example/page1/ 確實有任何問題嗎?

回答

0

對於添加尾隨斜線你可以有你的規則是這樣的:

DirectoryIndex index.php index.html 
DirectorySlash On 

Options -Indexes  
Options +FollowSymlinks 

RewriteEngine On 
RewriteBase/

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

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(page1|page2|page3)$ /$1/ [R=301,L,NC] 

#Show every html,htm and xml as php 
RewriteRule ^(.+?)\.(?:xml|html?)$ $1.php [NC,L] 
+0

仍然沒有工作,沒有我在的RewriteCond%的第一點{HTTP_HOST}^WWW \後SCAPE(+) $ [NC]? NE和NC代表什麼?也!-d都是遞歸目錄? fyi我在我的本地主機上測試 – Mik

+0

你在瀏覽器中輸入'http:// domain.com/page1'嗎? – anubhava

+0

我輸入http:// localhost/example/page1(和其他),並給我錯誤301 - 永久移動 – Mik