你能写一个到锚点的 301 重定向吗?
这是有效且正确的吗?
RewriteRule ^myOldPage.html$ /index.php#info [R]
我对 #info
部分特别感兴趣。
Is this valid and correct?
RewriteRule ^myOldPage.html$ /index.php#info [R]
I'm specifically interested about the #info
part.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。 这是一个有效的 301 重定向(HTTP 标准允许任何有效的 URI作为重定向提供)。
现在需要注意的是:并非所有搜索引擎都喜欢重定向。 Google 在处理锚标记方面做得非常出色(他们甚至有 对此的专利),而其他人会完全忽略它们。 只要这不是问题,重定向在技术上就是有效的。
更新:如果您在使用 mod_rewrite 时遇到问题,请尝试使用 NE(无转义)标志来防止 # 符号被编码:
Yes. That's a valid 301 redirect (the HTTP standard allows for any valid URI to be provided as the redirect).
Now the caveat: Not all search engines may love the redirect. Google does a fantastic job of handling anchor tags (they even have a patent on this), while others will completely ignore them. As long as that's not an issue, the redirect is technically valid.
Update: If you're having trouble with mod_rewrite, try the NE (no escape) flag to prevent the # symbol from getting encoded:
虽然看起来是正确的,但我有一种奇怪的感觉,这行不通。
浏览器需要了解#anchor。 服务器和 mod_rewrite 很可能会忽略它。
如果它不起作用,我想你可以做类似的事情......
然后在 php 输出一段 javascript 来进行锚点跳转。
Although it looks correct, I have a strange feeling this won't work.
The browser needs to know about the #anchor. The server and mod_rewrite may well just ignore it.
If it doesn't work I guess you could do something like..
and then in the php output a piece of javascript to do the anchor jump.