Friday, October 27, 2017

a tale of redirects

I added a second domain to Godaddy's deluxe hosting, using My Products -> Web Hosting -> Manage All ->  Manage (under primary domain name)  -> More -> Hosted Domains. The root folder for this was configured like /seconddomain, but when trying to access the second domain, was getting a redirect to
http://firstdomain.org/seconddomain

Godaddy support, over the course of 3 days, told me that this was due to some redirects in the .htaccess file. But they could not fix it for me. Finally when I tried editing the .htaccess file, found that the issues were due to some redirects meant for the CodeIgniter framework, redirecting html files to their php equivalents. The original .htaccess was
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

In order to make it work with the second domain, I added some conditions, and made it

# BEGIN WordPress

RewriteBase /
# END WordPress

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

RewriteCond %{HTTP_HOST} ^seconddomain.org$ [NC]
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_FILENAME} !-d
rewriterule ^(.*)$ /index.html [L]

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

RewriteCond %{HTTP_HOST} ^firstdomain.org$ [NC]
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_FILENAME} !-d
rewriterule ^(.*)$ /index.php?$1 [L]

Now both sites firstdomain.org and seconddomain.org seem to be working fine. www.firstdomain.org redirects to firstdomain.org and similarly www.seconddomain.org redirects to seconddomain.org.

No comments:

Post a Comment