Forum Moderators: phranque

Message Too Old, No Replies

Forward to www / htaccess trouble / dns redirect as well

problem rewriting url for secondary domain

         

junkmastajones11

6:57 pm on Jan 4, 2010 (gmt 0)

10+ Year Member



I have a domain hosted at http://www.example.com/
I also have a 2nd domain, www.example2.com hosted in a subdirectory of the example using dns at http://www.example.com/example2/

I need to have example2.com rewritten so that it redirects to www.example2.com

Problem
Using an .htaccess file example I found online, the following occurs:

  • example2.com is entered
  • example2.com is redirected to http://www.example2.com/example2/
  • This page obviously does not exist

    As you can see, there are inheritance issues. example2.com is inheriting the subdirectory of example.com.
    Does anyone know how to alter my .htaccess file so that the rewrite conditions do not cause inheritance of the example subdirectory?

    Also, I'm using the following code in my .htaccess file ( which is located in example's main directory... http://www.example.com/.htaccess )

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

    I understand half of that code. I just copied it from somewhere else online. Can someone provide me with any solutions?
    Do I need to put another .htaccess file in the subdirectory with the RewriteEngine Off?

    Thanks

    [edited by: jdMorgan at 3:30 pm (utc) on Jan. 5, 2010]
    [edit reason] example.com [/edit]

  • junkmastajones11

    8:54 pm on Jan 4, 2010 (gmt 0)

    10+ Year Member



    I feel a bit sheepish. I simply put the following code into the subdirectory "domain2" instead of the main directory of maindomain and that solved it.

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^example2.com [NC]
    RewriteRule ^(.*)$ http://www.example2.com/$1 [R=301,L]

    Still, if someone that has a better knowledge of writing .htaccess files, has anything to add here, that would be great too. For example, does anyone see anything wrong with that code?

    [edited by: jdMorgan at 3:32 pm (utc) on Jan. 5, 2010]
    [edit reason] example.com [/edit]

    g1smd

    9:09 pm on Jan 4, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    Replacing the single line with this

    RewriteCond %{HTTP_HOST} [b]!^[/b]www[b]\.[/b]domain2[b]\.[/b]com[b]$[/b]

    might be better, as it fixes a number of issues found in the original code.