[英]htaccess search and replace redirect
I need to redirect all traffic with an URL including "#" character and replace the character by XYZ. 我需要使用包含“#”字符的URL重定向所有流量,并用XYZ替换该字符。
For example, a request to 例如,请求
http://www.example.com/page.php?var=test#1
http://www.example.com/page.php?var=test#1
needs to be redirected to 需要重定向到
http://www.example.com/page.php?var=test#XYZ
http://www.example.com/page.php?var=test#XYZ
the # can be anywhere in the URL query #可以在URL查询中的任何位置
Is it possible to do it with an htaccess ? 可以用htaccess做到吗? AFAIK it won't work with PHP because anything next to # is ignored by the script (unless you have something to suggest me)
AFAIK它不适用于PHP,因为#旁的所有内容都会被脚本忽略(除非您有什么建议)
Is it possible to do it with an htaccess
有可能用htaccess做到吗
No. The #
and everything after it is a URL fragment . 否。
#
及其后的所有内容均为URL片段 。 It's never sent to the server, thus there's no way the webserver, or mod_rewrite (or, like you said, a script like php) even knows it's there. 它永远不会发送到服务器,因此,Web服务器或mod_rewrite(或者像您所说的php之类的脚本)甚至都无法知道它在那里。
You're going to have to do something that's strictly on the client's end in order to change a fragment (eg using javascript). 为了更改片段,您将必须严格执行客户端的操作(例如,使用javascript)。 The htaccess file can't help you at all.
htaccess文件根本无法帮助您。
For example, see the answer to this question: Remove fragment in URL with JavaScript w/out causing page reload 例如,请参见以下问题的答案: 使用带w / out的JavaScript删除URL中的片段,导致页面重新加载
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.