Styphon
Styphon

Reputation: 10447

htaccess apending parked domains subfolder to the URL

I created a website for a client and as per normal with our sites included an htaccess file to redirect any non-www traffic to the www. subdomain.

The client has now added a parked domain as a subfolder where they want to host another site. If you go to www.parkeddomain.com then it works, displaying the site in the PARKEDDOMAIN.COM subfolder. However if you go to parkeddomain.com then the htaccess redirects you to www.parkeddomain.com/PARKEDDOMAIN.COM. How can I stop it appending the subfolder to the URL?

This is the contents of the htaccess file:

Options +FollowSymLinks
RewriteEngine on

# Redirect old URLs to new URLs
Redirect /jewelry-the-experience /custom-made-jewelry
Redirect /jewelry-the-process /custom-made-jewelry

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*)$ /handle-url.php [L] 

Upvotes: 0

Views: 593

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

Add the following rule just before the existing one.

RewriteCond %{HTTP_HOST} ^parkeddomain\. [NC]
RewriteRule ^(?:parkeddomain\.com/?)?(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NC,L]

RewriteCond %{HTTP_HOST} !^(www|parkeddomain)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

We catch the no-www parked domain first and redirect without its sub-directory. This makes sure the existing rule is always redirecting the primary domain only.

Upvotes: 1

Related Questions