使用.htaccess文件使用哈希重定向URL

时间:2021-07-28 10:38:50

I'm trying to redirect a url containing an hash to another url.

我正在尝试将包含哈希的网址重定向到另一个网址。

Example: example.com/#test should redirect to example.com/teste_page

示例:example.com/#test应重定向到example.com/teste_page

Can this be done using htaccess file ?

可以使用htaccess文件完成吗?

3 个解决方案

#1


8  

No, hashes are never sent to the server, they are in-page fragment identifiers, so only used by the browser. So you're .htaccess would never have access to the hash. You'd have to do some nifty redirects to get that info to your server.

不,哈希从不发送到服务器,它们是页内片段标识符,因此仅供浏览器使用。所以你.htaccess永远不会访问哈希。您必须做一些漂亮的重定向才能将这些信息发送到您的服务器。

Here are some ideas that might spark something:

以下是一些可能引发某些想法的想法:

http://forum.modrewrite.com/viewtopic.php?t=3912

http://forum.modrewrite.com/viewtopic.php?t=3912

#2


32  

Yes it can be done, just use the No Escape flag... [NE,R,L]

是的,它可以完成,只需使用No Escape标志... [NE,R,L]

#3


-2  

This cannot be done with .htaccess - as far as the browser is concerned, the # and anything following it does not need to be sent to the server, as it's a link for the browser to resolve.

使用.htaccess无法做到这一点 - 就浏览器而言,#及其后面的任何内容都不需要发送到服务器,因为它是浏览器要解析的链接。

Here's a related question, as well as an example:

这是一个相关的问题,以及一个例子:

Note google thinks the request was: http://www.google.com/thisisa404?query=string#fragment

请注意,Google认为请求是:http://www.google.com/thisisa404?query = String #fragment

#1


8  

No, hashes are never sent to the server, they are in-page fragment identifiers, so only used by the browser. So you're .htaccess would never have access to the hash. You'd have to do some nifty redirects to get that info to your server.

不,哈希从不发送到服务器,它们是页内片段标识符,因此仅供浏览器使用。所以你.htaccess永远不会访问哈希。您必须做一些漂亮的重定向才能将这些信息发送到您的服务器。

Here are some ideas that might spark something:

以下是一些可能引发某些想法的想法:

http://forum.modrewrite.com/viewtopic.php?t=3912

http://forum.modrewrite.com/viewtopic.php?t=3912

#2


32  

Yes it can be done, just use the No Escape flag... [NE,R,L]

是的,它可以完成,只需使用No Escape标志... [NE,R,L]

#3


-2  

This cannot be done with .htaccess - as far as the browser is concerned, the # and anything following it does not need to be sent to the server, as it's a link for the browser to resolve.

使用.htaccess无法做到这一点 - 就浏览器而言,#及其后面的任何内容都不需要发送到服务器,因为它是浏览器要解析的链接。

Here's a related question, as well as an example:

这是一个相关的问题,以及一个例子:

Note google thinks the request was: http://www.google.com/thisisa404?query=string#fragment

请注意,Google认为请求是:http://www.google.com/thisisa404?query = String #fragment