elect elect - 1 year ago 98
Apache Configuration Question

Wordpress, redirect domain root to a subdomain

A friend of mine asked for help about his wordpress site. He did his work under

and now he'd like to have
redirected to it, if possible without showing
in the url bar

This is his domain root

# 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]

# 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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download