【问题标题】:Redirect index.html to index.html#2将 index.html 重定向到 index.html#2
【发布时间】:2014-03-09 02:37:15
【问题描述】:

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

www.arturhaddad.com
自动前往
www.arturhaddad.com/index.html#2

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

有什么解决办法吗?

【问题讨论】:

标签: html .htaccess redirect url-redirection


【解决方案1】:

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

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

还要确保在测试之前清除浏览器缓存或使用其他浏览器进行检查。

【讨论】:

  • 干得好,我如何也将其设置为 arturhaddad.com(它现在仅适用于 www.arturhaddad.com)?
  • @ArturHaddad 好的,请查看更新,以便两者都匹配。
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多