【问题标题】:301 redirect of sub domain to main domain but root to a specific folder301 子域重定向到主域但根到特定文件夹
【发布时间】:2022-01-26 02:09:38
【问题描述】:

我想将我的子域重定向到主域,根域除外。

我这样做了:

RewriteCond %{HTTP_HOST} ^sub.main.com$ [NC]
RewriteRule ^(.*)$ https://www.main.com/$1 [R=301,L]

所以这段代码将所有 URL 从 sub 重定向到 main,但我想要的根

sub.main.com

在这样的 URL 中发生

www.main.com/sub-category

我尝试了很多东西。一个是:

首先:sub.main.com 到 sub.main.com/index.php 之后:sub.main.com/index.php 到www.main.com/sub-category

我也发现了类似的东西,但我卡住了

Redirect site with .htaccess but exclude one folder

还有更多...

我做不到。

有人可以帮忙吗?

提前致谢。

【问题讨论】:

    标签: apache redirect http-status-code-301


    【解决方案1】:

    试试:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^sub.main.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^ https://www.main.com/sub-category [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^sub.main.com$ [NC]
    RewriteRule ^(.*)$ https://www.main.com/$1 [R=301,L]
    

    这将重定向:

    1. sub.main.com/xyzhttps://www.main.com/xyz
    2. sub.main.com/https://www.main.com/sub-category

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 2012-06-24
      • 2016-11-11
      相关资源
      最近更新 更多