这个htaccess重写是否正确?

时间:2011-11-25 06:28:56

标签: .htaccess mod-rewrite url-rewriting

我的htaccess文件中有以下内容。我想做的是制作

domain.com/index.php/view/whatever可通过domain.com/whatever访问 并且还会从non www重定向到www

这适用于其中包含index.php/view的所有网址,但现在其他没有index.php/view的网址却无效。例如:domain.com/index.php/site/pages不再有效,因为它中没有index.php/view

我希望htaccess仅影响其中包含index.php/view的网址而不影响其他网址。我需要做些什么才能解决这个问题?

RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/view/$1 [L]

RewriteCond %{http_host} ^domain.com [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

更新。为了缩小范围,我怎么能同时拥有这两个规则。我需要他们两个

RewriteRule ^(.*)$ /index.php/view/$1 
RewriteRule ^(.*)$ /index.php/site/$1 

1 个答案:

答案 0 :(得分:1)

因此,如果对http://domain.com/index.php/site/pages之类的内容发出请求,您希望它不受影响,但是如果它类似于http://domain.com/whatever,您希望它被重写吗?

您拥有的第一条规则匹配所有内容(文件和目录除外)。您可能希望使用以下内容缩小RewriteRule:

RewriteRule!^ index.php /index.php/view/$1 [L]

HTH

尼尔