递归重写URL [英] url rewrite recursively
问题描述
我正在尝试将网址从www.xxx.com/test.com重写为www.xxx.com/my.php?d=test.com 使用以下指令:
I am trying to rewrite url from www.xxx.com/test.com to www.xxx.com/my.php?d=test.com using the following directive:
Options Indexes FollowSymLinks
RewriteEngine On
RewriteRule ^((.+)\.(.+))$ my.php?d=$1
这不起作用,例如,URL为www.xxx.com/test.com 好像它被重写为www.xxx.com/my.php?d=test.com 然后将其重写为www.xx.com/my.php?d=my.php或类似的内容.这是否意味着该模式已被递归应用? 如何修复正则表达式?
this is not working, for example, the url is www.xxx.com/test.com it seems like it gets rewrite to www.xxx.com/my.php?d=test.com then gets rewrite to www.xx.com/my.php?d=my.php or something like that. does this mean the pattern is getting applied recursively?? how do I fix the regex?
推荐答案
Mod rewrite将反复通过重写引擎运行URI,直到在通过重写引擎之前和之后URI相同为止.这是正在发生的事情:
Mod rewrite will run a URI through the rewrite engine over and over until the URI is the same before and after it goes through the rewrite engine. This is what's happening:
- URI是 test.com
- 规则
^((.+)\.(.+))$
匹配,URI被重写为 my.php (带有一些查询字符串 d = test.com ) - 比较: test.com 与 my.php 不同,通过重写引擎将URI重新运行
- URI是 my.php
- 规则
^((.+)\.(.+))$
匹配,将URI重写为 my.php (带有一些查询字符串 d = my.php ) - 比较: my.php 与 my.php 相同,在URI匹配之前和之后,停止编写
- URI is test.com
- rule
^((.+)\.(.+))$
matches, URI rewritten to my.php (with some query string d = test.com) - compare: test.com is not the same as my.php, run the URI back through the rewrite engine
- URI is my.php
- rule
^((.+)\.(.+))$
matches, URI rewritten to my.php (with some query string d = my.php) - compare: my.php is the same as my.php, before and after URI match, stop writing
您的结果是/my.php?d=my.php
您需要添加一个条件,以便my.php不会应用该规则.在改写之前添加此内容
You need to add a condition so my.php doesn't get the rule applied. Add this before your rewriterule
RewriteCond %{REQUEST_URI} !^/my.php
这篇关于递归重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!