递归重写URL [英] url rewrite recursively

查看:68
本文介绍了递归重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将网址从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:

  1. URI是 test.com
  2. 规则^((.+)\.(.+))$匹配,URI被重写为 my.php (带有一些查询字符串 d = test.com )
  3. 比较: test.com my.php 不同,通过重写引擎将URI重新运行
  4. URI是 my.php
  5. 规则^((.+)\.(.+))$匹配,将URI重写为 my.php (带有一些查询字符串 d = my.php )
  6. 比较: my.php my.php 相同,在URI匹配之前和之后,停止编写
  1. URI is test.com
  2. rule ^((.+)\.(.+))$ matches, URI rewritten to my.php (with some query string d = test.com)
  3. compare: test.com is not the same as my.php, run the URI back through the rewrite engine
  4. URI is my.php
  5. rule ^((.+)\.(.+))$ matches, URI rewritten to my.php (with some query string d = my.php)
  6. 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屋!

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