为什么mod_rewrite的重写两​​次? [英] Why would mod_rewrite rewrite twice?

查看:94
本文介绍了为什么mod_rewrite的重写两​​次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才发现了URL重写的,所以我'已经仍然有很多东西需要学习。

I only recently found out about URL rewriting, so I've still got a lot to learn.

虽然继简易现代重写教程,他们的例子之一的结果实在是困惑我。

While following the Easy Mod Rewrite tutorial, the results of one of their examples is really confusing me.

RewriteBase /
RewriteRule (.*) index.php?page=$1 [QSA,L]

重写 /家居 /index.php?page=index.php&page=home

Rewrites /home as /index.php?page=index.php&page=home.

我想重复的可能已经引起了我的主机的CONFIGS的东西,但一个干净的安装的 XAMPP 不一样的。

I thought the duplicates might have had been caused by something in my host's configs, but a clean install of XAMPP does the same.

因此​​,没有人知道为什么这似乎解析两次吗?

So, does anyone know why this seems to parse twice?

和,对我来说这似乎是,如果它要做到这一点,那将是一个无限循环 - 为什么它停止在2个周期

And, to me this seems like, if it's going to do this, it would be an infinite loop -- why does it stop at 2 cycles?

推荐答案

=htt​​p://web.archive.org/web/20090302114812/http://easymodrewrite.com/notes-最后一个相对=nofollow>此页面,这是你的问题联系在一起教程的一部分:

From Example 1 on this page, which is part of the tutorial linked in your question:

假设。

RewriteRule ^(.*)$ index.php?PAGE=$1 [L,QSA]


  
  

然而,每次你运行的是,无论哪个文件,你的要求,PAGE变量总是含有的index.php。

Yet every time you run that, regardless of which file you request, the PAGE variable always contains "index.php".

为什么呢?你最终会做两重写。首先,你要求的 test.php的。这被改写为的index.php?PAGE = test.php的。第二次请求现在对于的index.php?PAGE =制成test.php的。这仍然是你重写模式相匹配,并且又被改写为的index.php?PAGE =的index.php

Why? You will end up doing two rewrites. Firstly, you request test.php. This gets rewritten to index.php?PAGE=test.php. A second request is now made for index.php?PAGE=test.php. This still matches your rewrite pattern, and in turn gets rewritten to index.php?PAGE=index.php.

一个解决办法是增加来检查,如果该文件已的index.php一个RewriteCond指令。一个更好的解决方案,也可以让你保持图像和CSS文件在同一目录下是使用检查文件是否存在,使用-f一个RewriteCond指令。

One solution would be to add a RewriteCond that checks if the file is already "index.php". A better solution that also allows you to keep images and CSS files in the same directory is to use a RewriteCond that checks if the file exists, using -f.

1 的链接是互联网档案馆,因为本教程的网站显示为脱机


1the link is to the Internet Archive, since the tutorial website appears to be offline

这篇关于为什么mod_rewrite的重写两​​次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆