【问题标题】:Redirect only home page to another site. not sub pages. example.com to newsite.com using .htaccess仅将主页重定向到另一个站点。不是子页面。使用 .htaccess 从 example.com 到 newsite.com
【发布时间】:2016-01-08 15:35:53
【问题描述】:

我想单独重定向主页。但不是子链接。我尝试了以下代码,但它不起作用。

   RewriteCond %{REQUEST_URI} ^/[/]?
   RewriteCond %{REQUEST_URI} !^/+[/]?
   RewriteRule (.*) http://www.newdomain.com/ [R=301,L]

所以我的要求是,

当用户访问时:http://test.site.co.uk 然后应该重定向到http://newsite.co.uk

当用户访问时:http://test.site.co.uk/mypage 然后应该重定向到http://newsite.co.uk/mypage

【问题讨论】:

    标签: wordpress .htaccess url-redirection


    【解决方案1】:

    短版

    RedirectMatch ^/$ http://newsite.com
    

    【讨论】:

      【解决方案2】:
          RewriteEngine On
          RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
          RewriteRule ^(.*)$ http://www.example.com/ [L,R=301]
      

      【讨论】:

        【解决方案3】:

        您可以使用以下重写规则:-

        RewriteCond %{HTTP_HOST} ^(example.com(\/{0,1})){1}$
        RewriteRule http://example2.com(\/{0,1}) [R=301,L]
        

        该 (/{0,1}) 部分用于匹配 example.com 和 example.com/(但没有 esle) - 如果您不希望匹配 example.com/ 从两行中删除该部分。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-09-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-24
          • 1970-01-01
          • 2023-04-08
          • 2016-01-19
          • 2014-08-10
          相关资源
          最近更新 更多