【问题标题】:Redirect old URL to new subdomain将旧 URL 重定向到新子域
【发布时间】:2013-03-07 14:52:59
【问题描述】:

我在example.com/blog 下有一个博客,但现在我更改为blog.example.com,它重定向到同一个旧文件夹。

我不希望用户直接访问旧 URL,因此,将 /blog 重定向到博客。我该怎么做?

我更喜欢使用 .htaccess。当前是 WordPress 默认:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

【问题讨论】:

  • 你能发布你当前的 .htaccess 吗?

标签: wordpress .htaccess mod-rewrite redirect subdomain


【解决方案1】:

你可以试试这个

    RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [R=301,L]

或 你可以做这样的事情来检查主域 - 这会检查你是否已经在 blog.example.com ,否则它会重定向。

    RewriteCond %{HTTP_HOST} !^blog\.example\.com$ [NC] 
    RewriteRule ^blog/$ http://blog.example.com [L,NC,R=301] 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 2023-02-23
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 2012-09-05
    相关资源
    最近更新 更多