将index.html重定向到index.html#2

时间:2014-03-09 02:37:15

标签: html .htaccess redirect url-redirection

我想知道如果用户键入是否可以进行重定向:

www.arturhaddad.com
自动转到 www.arturhaddad.com/index.html#2

尝试了cpanel重定向功能,但它将我重定向到http://www.arturhaddad.com/index.html%232

任何解决方案?

3 个答案:

答案 0 :(得分:1)

主要是通过javascript制作。 检查Javascript location.hash 变量,如果不存在,可以使用重定向或pushState在URL上添加这些变量。

您只能在服务器端进行重定向。您无法访问(仅通过javascript)来检查位置哈希。

答案 1 :(得分:1)

是的,这是可能的。您可以将其包含为重定向。使用NE标志可防止对其进行编码。把它放在你的htaccess文件中。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?arturhaddad\.com$ [NC]
RewriteRule ^$ http://www.arturhaddad.com/index.html#2 [NE,L,R=301]

另外,请确保在测试之前清除浏览器缓存,或者使用其他浏览器进行检查。

答案 2 :(得分:0)

将它放在index.html中,它会将您重定向到您想去的地方。

<meta http-equiv="refresh" content="0; url=LINK HERE" />
相关问题