使用mod_rewrite匹配代码

时间:2011-06-29 07:27:31

标签: apache mod-rewrite

对于我的应用程序,我想将URL与mod_rewrite匹配,以便通过GET请求将URL直接传递给文件(index.php)。这是我的代码:

RewriteEngine On
RewriteRule ^(.*)$ index.php?q=$1

然而,它不起作用,它似乎不确定地将其重写为“index.php?q = index.php”。有人能在这个问题上给我启发吗? 感谢。

1 个答案:

答案 0 :(得分:0)

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L]

试试这个例子