简体   繁体   English

Wordpress,将域根重定向到子域

[英]Wordpress, redirect domain root to a subdomain

A friend of mine asked for help about his wordpress site. 我的一个朋友向他的wordpress网站寻求帮助。 He did his work under sub.domain.com and now he'd like to have domain.com redirected to it, if possible without showing sub in the url bar 他在sub.domain.com下完成了他的工作,现在他想将domain.com重定向到它,如果可能的话,不在url栏中显示sub

This is his domain root .htaccess 这是他的域根.htaccess

# 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

Following some resources I found, I inserted these two lines after the RewriteEngine On : 根据我发现的一些资源,我在RewriteEngine On之后插入了这两行:

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R]

But it doesn't seem to work, it should be so simple but I am doing clearly something wrong... 但它似乎不起作用,它应该是如此简单,但我明显做错了......

I tried also commenting the rest, it didn't work 我试着评论其余的,它没有用

I am not an Apache expert at all, what's the problem? 我根本不是Apache专家,有什么问题?

To redirect example.com/ to sub.example.com/ ,you can use the following : 要将example.com/重定向到sub.example.com/ ,您可以使用以下内容:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^$ http://sub.domain.com/$1 [L,R]

^$ matches the root / of example.com ,if you want to redirect everything to subdomain ,change the pattern to ^(.*)$ . ^ $匹配example.com的root / ,如果要将所有内容重定向到子域,请将模式更改为^(。*)$

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

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