【问题标题】:htaccess how to redirect all pages, but not the root directoryhtaccess如何重定向所有页面,但不是根目录
【发布时间】:2012-08-17 02:29:50
【问题描述】:

我需要一个 htaccess 301 重定向的帮助。

我有一个网站 www.site.com,但我需要将所有页面更改为 www.newsite.com 但我不想移动 www.site.com(获取页面信息)

示例:

www.site.com (not move) index of to put then a template or message

www.site.com/2012/08/page.html move to www.newsite.com/2012/08/page.html
www.site.com/tag/keyword/ move to www.newsite.com/tag/keyword/
www.site.com/category/general/ move to www.newite.com/category/general/

我该怎么做?谢谢

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    您可以尝试使用 mod_alias'RedirectMatch 来强制 URI 中的某些内容进行重定向。在 site.com 的文档根目录下的 htaccess 文件中,添加:

    RedirectMatch 301 ^/(.+)$ http://www.newsite.com/$1
    

    这将使http://www.site.com/ 之后的任何内容都被重定向,但http://www.site.com/ 不会。但是,http://www.site.com/index.html 被重定向。如果这是个问题,您可以使用 mod_rewrite:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/$
    RewriteCond %{REQUEST_URI} !^/index.html$
    # and whatever else you don't want redirected
    RewriteRule ^(.*)$ http://www.newsite.com/$1 [L,R=301]
    

    【讨论】:

    • 使用此资产也会被重定向。没错,但可能不是操作人员想要的。
    【解决方案2】:

    www.site.com主机上通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT目录下的.htaccess中:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
    RewriteRule ^.+$ http://www.newsite.com%{REQUEST_URI} [L,R=301]
    

    【讨论】:

    • @anubhava:永远是我在这个网站上的救星。感激不尽。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    相关资源
    最近更新 更多