【发布时间】:2020-07-06 06:53:10
【问题描述】:
如果查询字符串或 index.php 之后的任何内容,重定向 url 与 htaccess 完全匹配不重定向
Redirect This Page: https://example.com/demo/index.php
To Page: https://example.com/ (home page)
But Do Not redirect: https://example.com/demo/index.php/*
Do NOT redirect: https://example.com/demo/index.php/password
Do NOT redirect https://example.com/demo/index.php?m=page
not redirect if any other combination
only redirect https://example.com/demo/index.php to https://example.com/
这个脚本不工作
RewriteEngine On
RewriteBase /
RewriteRule ^demo/index.php /demo/index.php?m=page[L,NC,END]
RewriteRule ^demo/index.php$ https://example.com/ [L,R=301]
【问题讨论】:
-
如果第二条规则没有按预期工作,您要么在浏览器中查看缓存结果,要么没有为该主机或位置启用重写模块。您是如何启用对分布式配置文件(“.htaccess”)的解释以及如何确保它们现在被考虑的?
-
重写模块使其他重定向工作正常。我在其他站点上进行了测试,没有缓存,也没有工作
-
啊,如果你有多个这样的规则(为什么不显示all?),那么可能是规则顺序的问题。请记住,规则是从上到下处理的。如果您在考虑该规则之前停止重写过程,它确实不会被应用......
-
你的问题真的一点都不清楚。如果您只想将
https://example.com/demo/index.php重定向到https://example.com/,则只需设置一条规则RewriteRule ^demo/index.php$ https://example.com/ [L,R=301] -
这条规则只删除 index.php demo/index.php 重定向到 demo/
标签: php regex apache .htaccess