mod_rewrite冲突
我试图为每个电影提供自己的网址名称,例如 www.helloworld.com/BATMAN。 我一直在使用 mod_rewrite 来创建这样的网址。我一直在使用以下 htaccess 代码来实现这样的结果。
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
mod_rewrite 工作完美。当用户输入随机电影名称(数据库中不存在的名称)时,例如www.helloworld.com/abcd,我创建了一个网址重定向,即www.helloworld.com/oopsmovienotfound.php。这也很好用。但我遇到的问题是这样的:当用户单击 www.helloworld.com/login.php 时。该 url 不断在 login.php 和 oopsmovienotfound.php 之间循环,或者该 url 被转发到 www.helloworld.com/oopsmovienotfound.php 因为数据库没有“login.php”作为电影名称。我认为这个命令
RewriteCond %{REQUEST_FILENAME} !-f
应该解决这个问题,但事实并非如此。请帮忙。以下是重写日志。
[18/Jan/2012:15:51:41 -0500] "GET /movie/batman HTTP/1.1" 200 102262
[18/Jan/2012:15:51:42 -0500] "GET /movie/text.css HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/selectMovie.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/selectMoiveName.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/finalselection.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/categories.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/background.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/tinylogo2.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/header.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/selectState.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/content_tail.jpg HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/movieimages/movieimage.jpg HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/tab.png HTTP/1.1" 304 -
[18/Jan/2012:15:52:24 -0500] "GET /movie/login.php HTTP/1.1" 200 3330
[18/Jan/2012:15:52:24 -0500] "GET /movie/login.php HTTP/1.1" 200 3330
[18/Jan/2012:15:52:24 -0500] "GET /movie/img/bg.jpg HTTP/1.1" 302 102262
[18/Jan/2012:15:52:29 -0500] "GET /movie/img/oops.php HTTP/1.1" 302 102262
[18/Jan/2012:15:52:29 -0500] "GET /movie/img/oops.php HTTP/1.1" 302 102262
[18/Jan/2012:15:52:33 -0500] "GET /movie/img/oops.php HTTP/1.1" 302 102262
当我输入 URL localhost/movie/index.php
时,URL 会转发到 localhost/movie/batman
因为 batman
是我观看的电影在我关闭上一个会话之前浏览。但是当我输入 localhost/movie/login.php 时,URL 不断循环。有趣的是,服务器中没有名为“img”的文件夹。当没有这样的路径时,为什么它不断循环通过 localhost/movie/img/oops.php ?
I am trying to give each MOVIE there own url name, for example, www.helloworld.com/BATMAN.
I have been using mod_rewrite to create such url. I have been using following htaccess code to achieve such result.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
The mod_rewrite works perfectly. When A user enters randam movie name (name that does not exist in database), for example, www.helloworld.com/abcd, I have created a url redirect which is www.helloworld.com/oopsmovienotfound.php. This works fine too. But the problem I am having is this: When user click www.helloworld.com/login.php .The url keeps looping between login.php and oopsmovienotfound.php OR the url is forwarded to www.helloworld.com/oopsmovienotfound.php beacause database doesnot have "login.php" as a movie name. I thought this command
RewriteCond %{REQUEST_FILENAME} !-f
should have take care of this but its not. Please help. Following is the rewrite log.
[18/Jan/2012:15:51:41 -0500] "GET /movie/batman HTTP/1.1" 200 102262
[18/Jan/2012:15:51:42 -0500] "GET /movie/text.css HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/selectMovie.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/selectMoiveName.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/finalselection.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/categories.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/background.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/tinylogo2.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/header.png HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/selectState.js HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/content_tail.jpg HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/movieimages/movieimage.jpg HTTP/1.1" 304 -
[18/Jan/2012:15:51:42 -0500] "GET /movie/tab.png HTTP/1.1" 304 -
[18/Jan/2012:15:52:24 -0500] "GET /movie/login.php HTTP/1.1" 200 3330
[18/Jan/2012:15:52:24 -0500] "GET /movie/login.php HTTP/1.1" 200 3330
[18/Jan/2012:15:52:24 -0500] "GET /movie/img/bg.jpg HTTP/1.1" 302 102262
[18/Jan/2012:15:52:29 -0500] "GET /movie/img/oops.php HTTP/1.1" 302 102262
[18/Jan/2012:15:52:29 -0500] "GET /movie/img/oops.php HTTP/1.1" 302 102262
[18/Jan/2012:15:52:33 -0500] "GET /movie/img/oops.php HTTP/1.1" 302 102262
When I enter the URL localhost/movie/index.php
the URL is forwarded to localhost/movie/batman
because batman
was the movie I was browsing before I closed my previous session. But when I enter localhost/movie/login.php
the URL keeps looping. Funny thing there is no such folder called "img" in the server. why does it keep looping through localhost/movie/img/oops.php
when there is no such path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先尝试执行相反的操作,例如,如果它是一个文件,请立即停止,如下所示:
如果这还不够:
两个提示:
如果您不在托管环境中(=如果它是您自己的服务器并且您可以修改虚拟主机,不仅仅是
.htaccess
文件),尝试使用RewriteLog
指令:它可以帮助您追踪此类问题:我最喜欢的检查正则表达式的工具:
http://www.quanetic.com/Regex (不要忘记选择 ereg(POSIX) 而不是 preg (PCRE)!)
Try to do the opposite first e.g. if it's a file, stop immediately, like this:
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the
.htaccess
files), try to use theRewriteLog
directive: it helps you to track down such problems:My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)