简体   繁体   English

将旧网址重定向到新的子域

[英]Redirect old URL to new subdomain

I have a blog under example.com/blog , but now I changed to blog.example.com , which redirects to the same old folder. 我在example.com/blog下有一个博客,但是现在我更改为blog.example.com ,它重定向到相同的旧文件夹。

I don't want users to access directly the old URL, so, redirecting /blog to blog. 我不希望用户直接访问旧的URL,因此,将/ blog重定向到博客。 How can I do it? 我该怎么做?

I would prefer using .htaccess. 我更喜欢使用.htaccess。 Current is WordPress default: 当前是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

You can try this 你可以试试这个

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

or You could do something like this that would check from the main domain - This checks if you are already at blog.example.com otherwise it will redirect. 或者您可以执行以下操作,从主域进行检查-检查您是否已经在blog.example.com上,否则它将重定向。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM