我已经制定了规则,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ user.php?userid=$1
它重定向http://localhost/username至 http://localhost/user.php?id=username工作正常, 但对于其他现有文件夹页面仍然重定向到 user.php 页面;不是现有文件夹,例如 http://localhost/folder它仍然重定向到 http://localhost/folder/?userid=folder , 它如何使其适用于现有目录,例如当我输入 http://localhost/folder 时那么页面应该显示/folder/目录???
最佳答案
将您的 .htaccess 代码替换为:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^(messages)/?$ index.php?page=$1 [L,NC,QSA]
RewriteRule ^(A-Z0-9_-]+)/?$ user.php?userid=$1 [L,NC,QSA]
如果仍然不起作用,请发布来自 access.log 的匹配长条目,并在您的 httpd.conf 中启用 RewriteLog 并在您的问题中发布日志。
关于Apache URL 重写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10462908/