我使用的是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