【问题标题】:How do I redirect example.com to example.com/subdirectory?如何将 example.com 重定向到 example.com/subdirectory?
【发布时间】:2011-02-28 22:08:31
【问题描述】:

我正在尝试将example.com(以及example.com/www.example.comwww.example.com/)重定向到example.com/subdirectory。我可以使用 HTML 轻松做到这一点,但根据我的阅读,最好使用 Apache 进行 301 重定向。

如何使用 Apache 做到这一点?

【问题讨论】:

    标签: apache url url-rewriting


    【解决方案1】:

    如果你想要 301 重定向:

    RedirectMatch 301 ^/$ /subdirectory/
    

    【讨论】:

      【解决方案2】:

      您应该使用带有RewriteRule 关键字的.htaccess 文件。有关如何执行此操作的更多信息,请参阅Apache docs

      【讨论】:

        【解决方案3】:
        Options +FollowSymLinks
        RewriteEngine on
        RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
        

        注意* 这种 .htaccess 重定向方法仅适用于启用了 Apache Mod-Rewrite 模块的 Linux 服务器。

        来源:http://www.webconfs.com/how-to-redirect-a-webpage.php

        示例用法是

        RewriteRule ^/$ http://somewhere.com/directory [R=301,L]
        

        我猜

        【讨论】:

          猜你喜欢
          • 2020-06-20
          • 2018-07-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-05
          • 2011-12-13
          • 2014-10-17
          • 1970-01-01
          相关资源
          最近更新 更多