SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .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 :

    Code:
    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!!!!

    Full time ADMIN - art community
    Part time coder - dsign

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    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/...-to-folder.php

  3. #3
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dujmovicv View Post
    ...Now when I point to the new_registered_domain_name.com, the browser automatically redirects me to my older site. ... how can I prevent the server to redirect me from new_registered_domain_name.com to my other site ...

    Code:
    ...
    RewriteCond %{HTTP_HOST} !^www\.my_old_site\.org$ [NC]
    RewriteRule .? http://www.my_old_site.org%{REQUEST_URI} [R=301,L]
    ...
    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.
    "First make it work. Then make it better."

  4. #4
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you guys for your replies. I have tried both deleting the above two lines and I have tried to modify my .htaccess like :
    Code:
    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....

    EDITED :

    Here's some progress :
    Code:
    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....

    Full time ADMIN - art community
    Part time coder - dsign

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dujmovicv View Post
    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...
    In that case, how about...

    !^(?:www\.)?my_addon_domain\.com$
    "First make it work. Then make it better."

  6. #6
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    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 :
    Code:
    RewriteCond %{HTTP_HOST} !(www\.my_addon_domain\.com)
    RewriteCond %{HTTP_HOST} !^(www\.maindomain\.org)?$
    RewriteRule (.*) http://www.maindomain.org/$1 [R=301,L]

    Full time ADMIN - art community
    Part time coder - dsign

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dujmovicv View Post
    Actually I need to edit these lines to make it work not only with www but without it too
    I believe what I posted should do that. The ? after the parentheses enclosing "www." makes it optional.
    "First make it work. Then make it better."

  8. #8
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    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

  9. #9
    a fresh, new start... dujmovicv's Avatar
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Jeff Mott OK pal, thanks! I managed to set it up properly.
    @EricWatson me too

    Full time ADMIN - art community
    Part time coder - dsign


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •