你能写一个到锚点的 301 重定向吗?

发布于 2024-07-10 12:54:40 字数 133 浏览 2 评论 0原文

这是有效且正确的吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞慾 2024-07-17 12:54:40

是的。 这是一个有效的 301 重定向(HTTP 标准允许任何有效的 URI作为重定向提供)。

现在需要注意的是:并非所有搜索引擎都喜欢重定向。 Google 在处理锚标记方面做得非常出色(他们甚至有 对此的专利),而其他人会完全忽略它们。 只要这不是问题,重定向在技术上就是有效的。

更新:如果您在使用 mod_rewrite 时遇到问题,请尝试使用 NE(无转义)标志来防止 # 符号被编码:

RewriteRule ^myOldPage.html$ /index.php#info [R,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:

RewriteRule ^myOldPage.html$ /index.php#info [R,NE]
沉鱼一梦 2024-07-17 12:54:40

虽然看起来是正确的,但我有一种奇怪的感觉,这行不通。

浏览器需要了解#anchor。 服务器和 mod_rewrite 很可能会忽略它。

如果它不起作用,我想你可以做类似的事情......

RewriteRule ^myOldPage.html$ /index.php?info=true [R]

然后在 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..

RewriteRule ^myOldPage.html$ /index.php?info=true [R]

and then in the php output a piece of javascript to do the anchor jump.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文