递归重写URL

编程入门 行业动态 更新时间:2024-10-28 19:29:01
本文介绍了递归重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将网址从www.xxx/test重写为www.xxx/my.php?d=test 使用以下指令:

I am trying to rewrite url from www.xxx/test to www.xxx/my.php?d=test using the following directive:

Options Indexes FollowSymLinks RewriteEngine On RewriteRule ^((.+)\.(.+))$ my.php?d=$1

这不起作用,例如,URL为www.xxx/test 好像它被重写为www.xxx/my.php?d=test 然后将其重写为www.xx/my.php?d=my.php或类似的内容.这是否意味着该模式已被递归应用? 如何修复正则表达式?

this is not working, for example, the url is www.xxx/test it seems like it gets rewrite to www.xxx/my.php?d=test then gets rewrite to www.xx/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
  • 规则^((.+)\.(.+))$匹配,URI被重写为 my.php (带有一些查询字符串 d = test )
  • 比较: test 与 my.php 不同,通过重写引擎将URI重新运行
  • URI是 my.php
  • 规则^((.+)\.(.+))$匹配,将URI重写为 my.php (带有一些查询字符串 d = my.php )
  • 比较: my.php 与 my.php 相同,在URI匹配之前和之后,停止编写
  • URI is test
  • rule ^((.+)\.(.+))$ matches, URI rewritten to my.php (with some query string d = test)
  • compare: test 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

    本文发布于:2023-10-31 17:09:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1546736.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:递归   重写   URL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!