.htaccess redirects to primary domain

Hi all,

I hope this is the right place for my post… I have a Primary domain hosted at this hosting company. Now I have registered a new domain name and want to host the new site at my existing account (I asked the guys at the hosting company, it IS possible to host as many sites as I want). I’ve created a new folder in the public_html folder and uploaded the index.php file. Now when I point to the new_registered_domain_name.com, the browser automatically redirects me to my older site. According to the guys at the hosting company it is because of my .htaccess file i the public_html folder. They solved it by renaming my .htaccess file to .htaccess_old … I don’t have to tell you that it caused my old site to stop functioning properly… My question is : how can I prevent the server to redirect me from new_registered_domain_name.com to my other site but keep the .htaccess file??? Here’s my .htaccess :


DirectoryIndex index.html.var index.htm index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml default.htm default.html home.htm index.php5 Default.html Default.htm home.html
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.my_old_site\\.org$ [NC]
RewriteRule .? http://www.my_old_site.org%{REQUEST_URI} [R=301,L]

RewriteRule ^([a-zA-Z_]+)$ index.php?page=$1 [L]

RewriteCond %{REQUEST_URI} public
RewriteRule ^([a-zA-Z_]+)/([-A-z0-9]+)$ index.php?page=$1&user=$2 [L]

RewriteCond %{REQUEST_URI} recommendations
RewriteRule ^([a-zA-Z_]+)/([-A-z0-9]+)$ index.php?page=$1&user=$2 [L]

Thank you in advance!!!

It looks like its because your htaccess is saying redirect index to folder. Here is how I fixed the same issues on my host account. I have multiple sites too. http://www.websitecodetutorials.com/code/htaccess/canonicalization-htaccess-mod_rewrite-301-redirect-non-www-to-www-and-index-to-folder.php

It’s redirecting to your old site because these two lines (highlighted in red) are telling it to. If that’s not the behavior you want, then you can delete those lines.

Thank you guys for your replies. I have tried both deleting the above two lines and I have tried to modify my .htaccess like :


DirectoryIndex index.html.var index.htm index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml default.htm default.html home.htm index.php5 Default.html Default.htm home.html
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine on

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

It still redirects to mydomain.com:frowning:

EDITED :

Here’s some progress :


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

I added the www prefix and now it is working but only with www.my_addon_domain.com but not for my_addon_domain.com…
I know this is a piece of cake for Apache/Server gurus but I’m NOT one…

In that case, how about…

!^(?:www\.)?my_addon_domain\.com$

Actually I need to edit these lines to make it work not only with www but without it too :


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

I believe what I posted should do that. The ? after the parentheses enclosing “www.” makes it optional.

I hate htaccess code. Finding it that is. There is usually 10 different pieces of code that does the same thing. You never know which one is the correct. Pulling answeres out of people that do know I thing or two about it is like pulling teeth. Thank god I think I have all of it I need

@Jeff Mott OK pal, thanks! I managed to set it up properly.
@EricWatson me too :slight_smile: