Mod Rewrite - Issue with Add-on domain www.domain.com vs domain.com

Discussion in 'PHP' started by starke, Aug 5, 2014.

  1. #1
    Hey everyone,
    Hope this isn't too basic, I'm having an issue with a mod rewrite of an add on domain hosted on Lunar Pages.

    Because it is an add-on domain to my main hosting account, the add-on domain appears in a folder off of my domain root. Since I have a mod rewrite for the main domain (everything with a www), the rewrite is affecting the add-on domains creating an unrecognizable address.

    The bad mod rewrite address looks something like this:
    www.addondomain.com/addondomain.com

    I've tried to edit my .htaccess as follows:
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} ^maindomain$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Code (markup):
    My attempted logic above is to force the rewrite only with a match to maindomain...

    Any thoughts on how to better achieve this? Thanks :)
     
    starke, Aug 5, 2014 IP
  2. snatcher

    snatcher Active Member

    Messages:
    219
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    90
    Digital Goods:
    1
    #2
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\.maindomain\.com [NC]
    RewriteRule (.*) http://www.maindomain.com/$1 [R=301,L]
    Code (markup):
     
    snatcher, Aug 6, 2014 IP
  3. starke

    starke Active Member

    Messages:
    228
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Actually, I'm getting the code to work now. I thought that my browser had been refreshed (looking for a new version of the page each time)... but maybe wasn't. Lol, of course now it seems to be working...

    Thank you snatcher and everyone for your thoughts.
     
    starke, Aug 7, 2014 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    This has nothing to do with PHP
     
    NetStar, Aug 8, 2014 IP
  5. chrisnagios

    chrisnagios Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
       RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    </IfModule>
    Code (markup):
    this one will work best for all cases
     
    chrisnagios, Aug 11, 2014 IP