我可能有这完全错误的:
Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule .* index.php [L] #Rewrites so it looks like production RewriteCond %{REQUEST_URI} !^/Home/ RewriteRule ^(.*)$ /Home/$1 [L]
有人可以设置我直接使所有的URL http:// site / somepage1 , http:// site / somepage2 ,被重写为http:// site / Home / somepage1 , http:// site / Home / somepage2 。 是否有一个规则可以捕获所有这些url,并在所有url上添加“/ Home”?
提前致谢。
更新
进入httpd.conf并设置“LogLevel = debug”显示这两个规则是冲突的:
[Fri Sep 23 10:54:07 2011] [debug] core.c(3065): [client 127.0.0.1] r->uri = /Home/index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home/index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /index.php [Fri Sep 23 10:54:07 2011] [debug] core.c(3071): [client 127.0.0.1] redirected from r->uri = /Home
有没有办法来结合这两个重写规则没有这个redirect错误?
像这样简单:
RewriteEngine On RewriteCond %{REQUEST_URI} !^/Home/ RewriteRule ^(.*)$ /Home/$1 [L]
很明显,如果你直接在/Home/里面请求URL(比如http://site/Home/somepage1 ,它将不会被重写到/Home/Home/somepage1 – 所以请记住,如果你有子文件夹与主文件夹相同。
更新:考虑到新的信息,让我们试试这种方法:
Options +FollowSymLinks RewriteEngine On # rewrite incoming link to /Home/ # but only if it's a non-existing file RewriteCond %{REQUEST_URI} !^/(Home/|index\.php) RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)$ /Home/$1 [L] # route all requests for non-existing resources to /index.php RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule .* index.php [L]