如何使用 mod_rewrite/htaccess 通过锚点检测 URL 并重定向?
我见过很多相反的例子,但我希望从锚点/哈希 URL 转到非锚点 URL,如下所示:
From: http://old.swfaddress-site.com/#/page/name
To: http://new.html-site.com/page/name
http://karoshiethos.com/2008/07/25/handling-urlencoded-swfaddress-links- with-mod_rewrite/ 对我有用。听起来好像 REQUEST_URI
中有 /#/stuff
,但我和我的 Apache (2.0.54) 都没有看到它。
有什么想法、过去的经验或成功吗?
I've seen a number of examples of the opposite, but I'm looking to go from an anchor/hash URL to a non-anchor URL, like so:
From: http://old.swfaddress-site.com/#/page/name
To: http://new.html-site.com/page/name
None of the examples at http://karoshiethos.com/2008/07/25/handling-urlencoded-swfaddress-links-with-mod_rewrite/ have functioned for me. It sounds like REQUEST_URI
has the /#/stuff
in it, but neither me nor my Apache (2.0.54) see it.
Any ideas, past experiences or successes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
#
之后的任何内容都是片段,并且不会被发送到网络服务器。您无法在任何时候捕获它,您必须使用客户端方法来捕获它们。Anything after the
#
is a fragment, and will not be sent to the webserver. You cannot capture it at any point there, you'll have to use a client-sided approach to capture those.@RobRuchte:使用 window.hash 不是更好吗? location.hash,用替换而不是正则表达式?
@RobRuchte : would it not be better to use window.location.hash, with a replace instead of a regular expression?
我是您链接到的帖子的作者。 Wrikken 是正确的,命名锚点后面的内容不会发送到服务器,除非一路上有什么东西破坏了 URL。在客户端,您的着陆页中需要一些像这样的 JavaScript,以将 swfaddress 链接重定向到另一个域上的相应 URL:
I'm the author of the post you linked to. Wrikken is correct, the content after the named anchor is not sent to the server unless something has mangled the URL along the way. On the client side, you need some JavaScript like this in your landing page to redirect the swfaddress links to corresponding URLs on another domain:
我使用了@m14t 答案的修改版本。这适用于类似于 http://example.com/path/to/page< 的重定向/a>#fragment --> http://example.com/path/to/page/fragment。请注意,我还连接了重定向的
window.location.pathname
,否则我将无法获得重定向的完整路径。如果新的文件路径与旧的完全不同,那么这将不起作用。就我而言,我需要在各个页面中构建碎片链接,这是改进网站搜索引擎优化通常所做的一部分。
I used a modified version of the answer by @m14t. This works for redirects that look like http://example.com/path/to/page#fragment --> http://example.com/path/to/page/fragment. Notice that I also concatenated the
window.location.pathname
for the redirect, otherwise I would not get the full path for the redirect. If the new file path is completely different from the old one, then this would not work.In my case, I needed to build fragmented links into individual pages, which is part of what is commonly done to improve a website's SEO.