我正在尝试将网址从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:
您的结果是/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
发布评论