简体   繁体   中英

Wordpress, redirect domain root to a subdomain

A friend of mine asked for help about his wordpress site. 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

This is his domain root .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 :

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?

To redirect example.com/ to sub.example.com/ ,you can use the following :

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 ^(.*)$ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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