http访问路由通过index.php不允许www. php


htaccess routing through index.php without allowing www

我通过GoDaddy有一个共享主机帐户,我在上面的网站使用。htaccess通过index.php路由所有请求。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L,QSA]

然后我想限制它使用非www url,所以我在它之前添加了以下内容:

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

所以总共是:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L,QSA]

然而,这两者一起不起作用。对于应该路由的URL,该URL尝试重定向到/missing.html。分开来看,这两个都很好。有没有一种方法可以让这两件事一起工作?

如果你想让它们一起工作,你应该删除第一个L标签。因为L表示,如果规则匹配,则不处理进一步的规则

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301]   //remove L from this line
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L,QSA]