我使用的是Kohana的框架(但我認爲這是不相關這一問題)和頁面可以像這樣從網站網址
http://www.example.com/articles/
http://www.example.com/index.php/articles/
訪問現在,我一般經驗法則刪除的index.php嘗試和調整我的.htaccess只允許一個頁面的方式,並默默地重定向其他常見的方式。
本質上,在上面的第一個URL中,地址實際上是在內部重定向到第二個示例。
我想要做的是強制任何第二種類型的URL變成第一種類型的URL。我不是在.htaccess經常有信心,我的第一次嘗試是投擲一些意想不到的結果(比如有時無限循環)
這裏是我想出了
RewriteRule ^index\.php/(.*) $1 [NC,L,R=301]
誰能告訴我我做錯了什麼,如果你也遇到過這個問題,你怎麼解決它?
編輯
我決定後我整個的.htaccess所以我所有的重定向可以檢查。
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /~toberua/
# file not found page
ErrorDocument 404 /404/
ErrorDocument 403 /403/
# get people out of my directories
Options -Indexes
# default page to load
DirectoryIndex index.php
# add trailing slash if missing
RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]
# redirect /favicon.ico requests
RewriteCond %{REQUEST_URI} !^/images/layout/favicon\.ico [NC]
RewriteCond %{REQUEST_URI} favicon\.(gif|ico|png|jpe?g) [NC]
RewriteRule (.*) images/layout/favicon.ico [R=301,L]
# send /home back to TLD
RewriteRule home/ $1 [NC,R=301,L]
# ensure there is no /index.php in the address bar
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ $1 [R=301,L] # this was my attempt to stop /dir/index.php and make it simply /dir/
RewriteRule ^index\.php/(.*) $1 [NS,NC,L,R=301]
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
NS做什麼混沌? – alex 2009-05-25 01:33:43