Michael
Michael

Reputation: 1

Redirect parked domain to subfolder - Wordpress problems

I'm probably missing something very simple. I have been through about 4^27 posts on mod_rewrite. But still can't make it work quite right.

I have two URLs both pointing to the same DNS entry. I have the standard .htaccess for redirecting a parked domain to a subfolder on my main domain. But when I go down two levels I run into problems. Here is my situation: I have MAIN domain and PARKED domain. I want every request to PARKED domain to end up at MAIN/PARKED, but still appear to the user as PARKED. So, when user enters PARKED/page, that is what should appear in address bar of browser, even though files live in MAIN/PARKED/page. I also want the browser-displayed URL to change to PARKED/subfolder/page even if the user manually enters MAIN/PARKED/subfolder/page. Here is the .htaccess in MAIN:

RewriteEngine On
Options +FollowSymLinks
RewriteBase /

# Display PARKED domain to user for all pages in MAIN/PARKED directory
RewriteCond %{HTTP_HOST} ^(www\.)?PARKED\.?(:[0-9]+)?$ [NC]
RewriteCond $1 !^PARKED/
RewriteRule ^(.*)$ PARKED/$1 [L]

# BEGIN WordPress
#RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

To complicate matters, I have my Wordpress site located in MAIN/PARKED. I did not change any rules in Wordpress, as I wanted .htaccess to handle it all.

The .htaccess above appears to work correctly in all situations except when the user manually enters my 2-deep example above: MAIN/PARKED/subfolder/page or just MAIN/PARKED. Then I receive a 404. If you enter PARKED/subfolder/page, it behaves perfectly.

TIA for any words of wisdom.

Michael

Upvotes: 0

Views: 707

Answers (1)

user3431976
user3431976

Reputation: 191

# BEGIN WordPress
<IfModule mod_rewrite.c>
# tell mod_rewrite to activate and give base for relative paths

RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?PARKED.com$
RewriteCond %{REQUEST_URI} !^/PARKED/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /PARKED/$1 

RewriteCond %{HTTP_HOST} ^(www.)?PARKED.com$
RewriteRule ^(/)?$ PARKED/index.php [L]

# for main domain

RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]

</IfModule>

# END WordPress

Upvotes: 1

Related Questions