Apache URL 重写问题

标签 apache .htaccess mod-rewrite url-rewriting

我已经制定了规则,

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ user.php?userid=$1

它重定向http://localhost/usernamehttp://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/

相关文章:

.htaccess - Htaccess 重定向具有匹配字符串的 url

wordpress - 我应该在 WordPress 中使用选项 - 索引吗?

php - 站点安全正则表达式处理程序? (PHP)

php - "Your PHP installation appears to be missing the MySQL extension which is required by WordPress."

php - 重定向到新域上的相同路径

.htaccess 重写 Tomcat 服务器

.htaccess - 添加 www.删除 .html

wordpress - Laravel 和 Wordpress 在同一服务器/域上

windows - Apache Httpd.conf 相对路径

apache - htaccess 强制 https 和 www。在域和 http 子域上没有 www