【问题标题】:How can I rewrite all urls to "/"?如何将所有网址重写为“/”?
【发布时间】:2010-10-11 20:20:48
【问题描述】:

服务器:Apache

我希望通过以下方式重写我的网址,但我无法找到让它工作的方法。

http://website.com/index.html

我希望它重定向到:

http://website.com/

所以基本上我想加载 index.html,但不在 url 中显示它。我也不想给它取另一个名字。我不是在寻找 /index.html 变成 /index

此外,我正在尝试获取任何 GET 数据,例如:

http://website.com/index.html?id=0&name="fred"

重写为:

http://website.com/?id=0&name="fred".

如果您有一个不使用 .htaccess 文件的解决方案,也可以。

【问题讨论】:

    标签: html apache mod-rewrite url-rewriting


    【解决方案1】:

    我相信这应该可行:

    RewriteEngine on
    RewriteRule ^index\.html(.*)$ /$1 [R=permanent,L]
    

    这会将所有以/index.html 开头的请求重定向到简单的“/”,并将保留index.html 之后的所有参数

    【讨论】:

    • 起始斜线绝对不应该在那里。
    【解决方案2】:

    对于 .htaccess 文件:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} ^GET\ /index\.html
    RewriteRule ^index\.html$ / [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-10
      • 2016-11-03
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 2012-07-02
      相关资源
      最近更新 更多