我有一个具有以下(简化)布局的web服务器:
/
www/ # will hold html and PHP files (web content)
doc/ # some documentation
lib/ # some libraries
我想使用htaccess将每个请求"重定向"到www.mydomain.com/page到www.mydomain.com/swww/page.php。
我尝试过以下几种:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)$ www/$1.php
但它会产生500内部服务器错误。
出于调试目的,我创建了一个www/test.php页面,该页面会呼应每个GET变量,并修改了我的.htaccess:
RewriteRule ^(.*)$ www/test.php?page=$1
只是为了检查我是否匹配了正确的东西。当对www.mydomain.com/somepage执行请求时,预期的行为是page=somepage,而我得到的是page=www/get.php。
为什么会有这种行为?我怎样才能完成我需要的?
您必须排除要重写的路径:
RewriteRule ^((?!www).*)$ www/test.php?page=$1 [NC,L]
否则您将得到一个无限循环错误,因为www/test.php也匹配重写模式(.*)