2014-01-31 92 views
2

我試圖刪除.PHP .html和使用htaccess的URL從斜線traling,怎麼過這個代碼工作正常,爲PHP而不是HTML和斜線htaccess的刪除.PHP,.html和斜線

對於PHP

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteCond %{REQUEST_URI} !/system/.* [NC] 
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] 
# Directs all EE web requests through the site index file 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 

對於HTML

RewriteCond %{REQUEST_URI} index.html 
RewriteRule ^(.*)index.html$ /$1/ [R=301,L] 
+0

RedirectMatch 301 ^(。*)/ $/$ 1正在爲我的尾部斜槓 – Vishal

回答

5

有這樣說:

# externally redirect /dir/file.php to /dir/file and remove index 
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:html?|php)/?[\s?] [NC] 
RewriteRule^/%1%2 [R=301,L,NE] 

# remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s] 
RewriteRule ^(.+?)/$ /$1 [R=301,L] 

# internally add php extension 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 

# internally add html extension 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.html -f 
RewriteRule ^(.+?)/?$ $1.html [L] 
+0

嗨感謝您的回覆,這裏的index.html網址不工作,當我輸入url像http://www.mywdesign.com /index.html/web-dev-ecommerce-services它顯示頁面未找到,當我在瀏覽器中使用像http://www.mywdesign.com/index.php/web-dev-ecommerce-services這樣的網址時,它會轉到http://www.mywdesign.com//web-dev-ecommerce-services,所以雙斜槓來。你能幫忙嗎? – Vishal

+0

看到更新它將解決'/ /'問題。然而對於'/ index.html/web-dev-ecommerce-services'按照需求它會重定向到'/ web-dev-ecommerce-services'這是不是發生了?或者你想讓它保持爲'/ index.html/web-dev-ecommerce-services'本身? – anubhava

+0

嗨,index.php和尾部斜槓現在工作正常,但index.html不會重定向到/ web-dev-ecommece-service但是同樣的事情可以用php很好但在index.html的情況下它不工作 – Vishal