[英]Apache RedirectMatch with Regex
I'm trying to redirect every URL that have no #
to the same, but with #
after /path/
.我试图将每个没有
#
URL 重定向到相同的 URL,但在/path/
之后带有#
。
Example:示例:
This URL: https://www.example.com/path/test/test
这个网址:
https://www.example.com/path/test/test
: https://www.example.com/path/test/test
Need redirect to this url: https://www.example.com/path/#/test/test
需要重定向到这个网址:
https://www.example.com/path/#/test/test
: https://www.example.com/path/#/test/test
So I wrote this Redirect Match:所以我写了这个重定向匹配:
RedirectMatch permanent ^/path/(?!#)(.*)$ /path/#/$2
But it's not working.但它不起作用。
Browser shows me this message: ERR_TOO_MANY_REDIRECTS
浏览器向我显示此消息:
ERR_TOO_MANY_REDIRECTS
You can just use this rule in your site root .htaccess:您可以在站点根目录 .htaccess 中使用此规则:
RewriteEngine On
RewriteRule ^/?(path)/(.+)$ /$1/#/$2 [L,NE,NC,R=301]
It will redirect /path/test/test
to /path/#test/test
.它会将
/path/test/test
重定向到/path/#test/test
。
There is no need to check for presence of #
in RewriteRule
because client browsers don't send any part after #
to web server anyway.无需在
RewriteRule
检查#
是否存在,因为客户端浏览器无论如何都不会将#
之后的任何部分发送到 Web 服务器。
You can try this:你可以试试这个:
RedirectMatch ^/path/([^#]+)$ /path/#/$1
The captured group ([^#]+)
represents any string, minimum 1 character, that doesn't contain #
.捕获的组
([^#]+)
表示任何字符串,最少 1 个字符,不包含#
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.