【问题标题】:Redirect 301 specific pages and the rest to just one page重定向 301 特定页面,其余页面仅重定向到一页
【发布时间】:2017-09-09 02:41:24
【问题描述】:

首先我需要将这些页面重定向到不同域中的另一个页面

Redirect 301 /example1 http://newdomain.com/test1
Redirect 301 /example2 http://newdomain.com/random1

注意新域中的页面不同(例如,/example1 到 /test1)

之后,我需要将其余页面重定向到newdomain.com

例如,将 301(其他所有内容)重定向到 http://newdomain.com

【问题讨论】:

    标签: .htaccess redirect http-status-code-301


    【解决方案1】:

    试试下面的规则,使用mod rewrite 我假设你启用了mod重写。

    RewriteEngine On
    RewriteRule ^example1$ http://newdomain.com/test1 [R=301,L]
    RewriteRule ^example2$ http://newdomain.com/random1 [R=301,L]
    RewriteCond %{REQUEST_URI} !^(example1|example2)
    RewriteRule ^ http://newdomain.com [R=301,L]
    

    【讨论】:

    • 另外,有没有办法不指定这一行中的页面RewriteCond %{REQUEST_URI} !^(example1|example2),因为它们很多
    • 好吧,再试一次我编辑的规则,请在提问时说明您的全部要求,因为这不是代码编写服务,您可能必须自己尝试或提出新问题。
    【解决方案2】:

    在您的 .htaccess 中试试这个

    RewriteEngine On
    RewriteRule ^(.*)$ http://newdomain.com/ [R=301]
    

    【讨论】:

    • 抱歉,这只是重定向所有内容
    • @IMB 这只是一个例子,你需要根据你的需要修改它
    【解决方案3】:

    如果你想使用 mod-alias ,你可以使用这些重定向:

    RedirectMatch 301 ^/example1/?$ http://example.com/test1
    RedirectMatch 301 ^/example2/?$ http://example.com/random1
    #redirect everything else to the homepage of example.com
    RedirectMatch ^.+$ http://example.com/
    

    在测试这些重定向之前清除浏览器缓存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      相关资源
      最近更新 更多