【问题标题】:rewrite url using htaccess or hide some text from url使用 htaccess 重写 url 或隐藏 url 中的一些文本
【发布时间】:2016-08-03 06:52:03
【问题描述】:
 The url showing in the address bar: www.testsite.com/news#tab-1
 The url which I want to show: www.testsite.com/news
 The url showing in the address bar: www.testsite.com/news#tab-2
 The url which I want to show: www.testsite.com/events

我尝试使用 htaccess 重写规则

 RewriteCond %{REQUEST_URI} /news#tab-2$
 RewriteRule .* /news[L]

 RewriteRule www.testsite.com/test www.testsite.com/news#tab-1

但它没有工作。请帮忙。

【问题讨论】:

    标签: apache .htaccess url-rewriting


    【解决方案1】:

    你不能用 .htaccess 重写锚。你需要使用一些客户端,比如 javascript 才能这样做。

    这篇文章是我在另一个类似的问题中找到的,你可以在这里阅读: Remove fragment in URL with JavaScript w/out causing page reload

    【讨论】:

      【解决方案2】:

      客户端浏览器不会向服务器发送字符“#”。如果您有权访问服务器日志,您将看到服务器获取的所有内容都是“GET /news”并忽略其余部分。 “#”是客户端解释字符。

      如果您坚持将其发送到服务器,则必须在 url 中对其进行十六进制编码,但如果您使用更常见的 URI 路径甚至查询字符串“?”可能会更好。如果你想从服务器做内部重定向。

      作为一个友好的旁注。除非您不是 Apache HTTPD 服务器的管理员,否则请勿使用 .htaccess。不需要重定向/重写,因为这会使它们复杂化,并且会为服务器带来更大的开销,因为需要不断检查文件是否有更改。

      【讨论】:

        猜你喜欢
        • 2016-02-28
        • 1970-01-01
        • 2016-10-03
        • 2013-08-13
        • 2013-12-24
        • 1970-01-01
        • 2012-06-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多