一台服务器上有奇怪的 mod_rewrite 问题,但另一台服务器上没有
我编写了一些在一台服务器上运行良好的 mod_rewrites,但另一台
mod_rewrite 通常无法正常工作,例如转到 http://site/ about 将我带到服务器 A 和服务器 B 上的 about.php
但是当 mod_rewrite 向前推进另一个级别时,服务器 B 上会发生一些奇怪的事情
例如,在服务器 A 上,当我访问 http://site/submit/bulk 它带我到submit_bulk.php,但是当我访问服务器B上的同一位置时,它带我提交.php。就像在第二台服务器上它选择第一个 mod_rewrite 匹配 (/submit) 并且不会继续寻找实际匹配 (/submit/bulk)。
同样的问题也发生在底部的 rss 位上,rss/submissions/nick 在服务器 A 上工作正常,但在服务器 B 上显然只是转到 rss.php,没有传递任何参数,
你能看出可能出了什么问题吗?
谢谢
IndexIgnore *
ErrorDocument 404 /404.php
RewriteEngine on
RewriteRule ^all-time/?$ "index.php?mode=all-time"
RewriteRule ^all-time/cat/([^/\.]+)/?$ index.php?mode=all-time&cat=$1 [L]
RewriteRule ^all-time/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=all-time&cat=$1&p=$2 [L]
RewriteRule ^all-time/p/([^/\.]+)/?$ index.php?mode=all-time&p=$1 [L]
RewriteRule ^cat/([^/\.]+)/?$ index.php?cat=$1 [L]
RewriteRule ^cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?cat=$1&p=$2 [L]
RewriteRule ^comment/?$ "comment.php"
RewriteRule ^comments/?$ "comment_list.php"
RewriteRule ^delete/c/([^/\.]+)/?$ delete_comment.php?comment=$1 [L]
RewriteRule ^delete/p/([^/\.]+)/?$ delete_post.php?post=$1 [L]
RewriteRule ^delete/u/([^/\.]+)/?$ delete_user.php?user=$1 [L]
RewriteRule ^edit/p/([^/\.]+)/?$ submit.php?post=$1 [L]
RewriteRule ^edit/u/([^/\.]+)/?$ edit_user.php?user=$1 [L]
RewriteRule ^forgot/?$ "forgot.php"
RewriteRule ^login/?$ "login.php"
RewriteRule ^new/?$ "index.php?mode=new"
RewriteRule ^new/p/([^/\.]+)/?$ index.php?mode=new&p=$1 [L]
RewriteRule ^new/cat/([^/\.]+)/?$ index.php?mode=new&cat=$1 [L]
RewriteRule ^new/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=new&cat=$1&p=$2 [L]
RewriteRule ^p/([^/\.]+)/?$ index.php?p=$1 [L]
RewriteRule ^register/?$ "register.php"
RewriteRule ^reset/about/?$ "reset_about.php"
RewriteRule ^reset/email/?$ "reset_email.php"
RewriteRule ^reset/forgot?$ "reset_forgot.php"
RewriteRule ^reset/pw/?$ "reset_pw.php"
RewriteRule ^search/?$ "search.php"
RewriteRule ^submit/?$ "submit.php"
RewriteRule ^submit/bulk/?$ "submit_bulk.php"
RewriteRule ^submissions/([^/\.]+)/?$ index.php?mode=submit&user=$1 [L]
RewriteRule ^submissions/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=submit&user=$1&p=$2 [L]
RewriteRule ^submissions/([^/\.]+)/cat/([^/\.]+)/?$ index.php?mode=submit&user=$1&cat=$2 [L]
RewriteRule ^submissions/([^/\.]+)/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=submit&user=$1&cat=$2&p=$3 [L]
RewriteRule ^u/([^/\.]+)/?$ profile.php?user=$1 [L]
RewriteRule ^u/([^/\.]+)/comments/?$ comment_list.php?user=$1 [L]
RewriteRule ^u/([^/\.]+)/comments/p/([^/\.]+)/?$ comment_list.php?user=$1&p=$2 [L]
RewriteRule ^ulist/?$ "user_list.php"
RewriteRule ^v/([^/\.]+)/?$ view.php?post=$1 [L]
RewriteRule ^voted/([^/\.]+)/?$ index.php?mode=vote&user=$1 [L]
RewriteRule ^voted/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=vote&user=$1&p=$2 [L]
RewriteRule ^voted/([^/\.]+)/cat/([^/\.]+)/?$ index.php?mode=vote&user=$1&cat=$2 [L]
RewriteRule ^voted/([^/\.]+)/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=vote&user=$1&cat=$2&p=$3 [L]
RewriteRule ^rss/?$ "rss.php"
RewriteRule ^rss/all-time/?$ "rss.php?mode=all-time"
RewriteRule ^rss/all-time/cat/([^/\.]+)/?$ rss.php?mode=all-time&cat=$1 [L]
RewriteRule ^rss/cat/([^/\.]+)/?$ rss.php?cat=$1 [L]
RewriteRule ^rss/new/?$ "rss.php?mode=new"
RewriteRule ^rss/new/cat/([^/\.]+)/?$ rss.php?mode=new&cat=$1 [L]
RewriteRule ^rss/submissions/([^/\.]+)/?$ rss.php?mode=submit&user=$1 [L]
RewriteRule ^rss/submissions/([^/\.]+)/cat/([^/\.]+)/?$ rss.php?mode=submit&user=$1&cat=$2 [L]
RewriteRule ^rss/voted/([^/\.]+)/?$ rss.php?mode=vote&user=$1 [L]
RewriteRule ^rss/voted/([^/\.]+)/cat/([^/\.]+)/?$ rss.php?mode=vote&user=$1&cat=$2 [L]
I have written some mod_rewrites that work fine on one server, but not another
mod_rewrite is working in general, for example going to http://site/about brings me to about.php on Server A and on Server B
But something strange is happening on Server B when the mod_rewrite goes another level forward
For example, on Server A, when I visit http://site/submit/bulk it brings me to submit_bulk.php, but when I visit that same location on Server B it brings me to submit.php. It's like on the second server it picks the first mod_rewrite match (/submit) and doesn't keep looking for the actual match (/submit/bulk).
The same problems happen with the rss bits at the bottom, rss/submissions/nick works correctly on Server A, but on Server B its obviously just going to rss.php with no params passed
Can you see what might be wrong?
Thank you
IndexIgnore *
ErrorDocument 404 /404.php
RewriteEngine on
RewriteRule ^all-time/?$ "index.php?mode=all-time"
RewriteRule ^all-time/cat/([^/\.]+)/?$ index.php?mode=all-time&cat=$1 [L]
RewriteRule ^all-time/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=all-time&cat=$1&p=$2 [L]
RewriteRule ^all-time/p/([^/\.]+)/?$ index.php?mode=all-time&p=$1 [L]
RewriteRule ^cat/([^/\.]+)/?$ index.php?cat=$1 [L]
RewriteRule ^cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?cat=$1&p=$2 [L]
RewriteRule ^comment/?$ "comment.php"
RewriteRule ^comments/?$ "comment_list.php"
RewriteRule ^delete/c/([^/\.]+)/?$ delete_comment.php?comment=$1 [L]
RewriteRule ^delete/p/([^/\.]+)/?$ delete_post.php?post=$1 [L]
RewriteRule ^delete/u/([^/\.]+)/?$ delete_user.php?user=$1 [L]
RewriteRule ^edit/p/([^/\.]+)/?$ submit.php?post=$1 [L]
RewriteRule ^edit/u/([^/\.]+)/?$ edit_user.php?user=$1 [L]
RewriteRule ^forgot/?$ "forgot.php"
RewriteRule ^login/?$ "login.php"
RewriteRule ^new/?$ "index.php?mode=new"
RewriteRule ^new/p/([^/\.]+)/?$ index.php?mode=new&p=$1 [L]
RewriteRule ^new/cat/([^/\.]+)/?$ index.php?mode=new&cat=$1 [L]
RewriteRule ^new/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=new&cat=$1&p=$2 [L]
RewriteRule ^p/([^/\.]+)/?$ index.php?p=$1 [L]
RewriteRule ^register/?$ "register.php"
RewriteRule ^reset/about/?$ "reset_about.php"
RewriteRule ^reset/email/?$ "reset_email.php"
RewriteRule ^reset/forgot?$ "reset_forgot.php"
RewriteRule ^reset/pw/?$ "reset_pw.php"
RewriteRule ^search/?$ "search.php"
RewriteRule ^submit/?$ "submit.php"
RewriteRule ^submit/bulk/?$ "submit_bulk.php"
RewriteRule ^submissions/([^/\.]+)/?$ index.php?mode=submit&user=$1 [L]
RewriteRule ^submissions/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=submit&user=$1&p=$2 [L]
RewriteRule ^submissions/([^/\.]+)/cat/([^/\.]+)/?$ index.php?mode=submit&user=$1&cat=$2 [L]
RewriteRule ^submissions/([^/\.]+)/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=submit&user=$1&cat=$2&p=$3 [L]
RewriteRule ^u/([^/\.]+)/?$ profile.php?user=$1 [L]
RewriteRule ^u/([^/\.]+)/comments/?$ comment_list.php?user=$1 [L]
RewriteRule ^u/([^/\.]+)/comments/p/([^/\.]+)/?$ comment_list.php?user=$1&p=$2 [L]
RewriteRule ^ulist/?$ "user_list.php"
RewriteRule ^v/([^/\.]+)/?$ view.php?post=$1 [L]
RewriteRule ^voted/([^/\.]+)/?$ index.php?mode=vote&user=$1 [L]
RewriteRule ^voted/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=vote&user=$1&p=$2 [L]
RewriteRule ^voted/([^/\.]+)/cat/([^/\.]+)/?$ index.php?mode=vote&user=$1&cat=$2 [L]
RewriteRule ^voted/([^/\.]+)/cat/([^/\.]+)/p/([^/\.]+)/?$ index.php?mode=vote&user=$1&cat=$2&p=$3 [L]
RewriteRule ^rss/?$ "rss.php"
RewriteRule ^rss/all-time/?$ "rss.php?mode=all-time"
RewriteRule ^rss/all-time/cat/([^/\.]+)/?$ rss.php?mode=all-time&cat=$1 [L]
RewriteRule ^rss/cat/([^/\.]+)/?$ rss.php?cat=$1 [L]
RewriteRule ^rss/new/?$ "rss.php?mode=new"
RewriteRule ^rss/new/cat/([^/\.]+)/?$ rss.php?mode=new&cat=$1 [L]
RewriteRule ^rss/submissions/([^/\.]+)/?$ rss.php?mode=submit&user=$1 [L]
RewriteRule ^rss/submissions/([^/\.]+)/cat/([^/\.]+)/?$ rss.php?mode=submit&user=$1&cat=$2 [L]
RewriteRule ^rss/voted/([^/\.]+)/?$ rss.php?mode=vote&user=$1 [L]
RewriteRule ^rss/voted/([^/\.]+)/cat/([^/\.]+)/?$ rss.php?mode=vote&user=$1&cat=$2 [L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否不想将更具体的条件移至列表中的更高位置,以最大程度地减少重定向次数?即先将 /server/bulk 条件放在前面,这样它就不会达到 /submit 条件。
否则,有一个名为 MaxRedirects 的 mod_rewrite 选项可以检查 httpd.conf 或 .htaccess 中,它可以防止重定向进入无限循环。我相信 MaxRedirects 默认设置为 10,但可能在服务器上设置为 1,这很奇怪。您可以通过设置
RewriteOptions MaxRedirects=10
在 .htaccess 中覆盖它。Wouldn't you want to move the more specific conditions higher on the list so as to minimize the number of redirects? i.e. put the /server/bulk condition first so it won't even hit the /submit condition.
Otherwise, there's a mod_rewrite option to check in either httpd.conf or in .htaccess called MaxRedirects, which prevents redirects from going into infinite loops. I believe MaxRedirects is set to 10 by default, but could possibly be set to 1 on the server that's being weird. You may be able to override it in .htaccess by setting
RewriteOptions MaxRedirects=10
.在我的 000-default 文件中,我注意到:
选项索引 FollowSymLinks 多视图
允许覆盖全部
订单允许、拒绝
允许来自所有人
删除 MultiViews 似乎可以解决问题
In my 000-default file I notice:
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
Removing MultiViews seems to fix the problem