htaccess rewrite example.com/user.php?id=username to example.com/username

时间:2014-01-30 03:00:27

标签: php .htaccess mod-rewrite url-rewriting

标题说我无法重写以下网址

原始网址: example.com/user.php?id=username

重写的网址: example.com/username

我的.htcacess代码是:

RewriteEngine On
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]

问题是什么?

1 个答案:

答案 0 :(得分:1)

重写引擎将循环,这意味着重写的URI(/user.php)匹配相同的模式并再次应用。尝试添加一些条件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]