Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite on addon sites

addon sites getting redirected to folder

         

defanjos

5:08 am on Nov 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a shared hosting account with cpanel
The main site is http://www.example.com
I am using the following to redirect from non-www to www version:

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

It works. The problem is, when I add new sites under the shared account (cpanel), they get redirected from httx://www.newsite1.com to httx://www.example.com/newsite1 and httx://www.newsite2.com to httx://www.example.com/newsite2, etc.

How can I exclude these new sites from being redirected? I tried all kinds of rules to exclude the folders newsite1 and newsite2, but nothing works.

Samizdata

1:15 pm on Nov 26, 2008 (gmt 0)

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



Untested, but I would have thought that simple exclusions would work:

# If request does not include newsite1
RewriteCond %{HTTP_HOST} !newsite1 [NC]
# And does not include newsite2
RewriteCond %{HTTP_HOST} !newsite2 [NC]
# Run the routine
RewriteCond %{HTTP_HOST} !^(.*)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

However, I do not use cPanel and don't know how it might interfere.

...

defanjos

5:56 pm on Nov 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Samizdata,
Thanks, it worked.

g1smd

6:46 pm on Nov 26, 2008 (gmt 0)

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



Note that
^(.*)$
simplifies to
(.*)
too.

jdMorgan

3:48 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A few tweaks:

# If request does not include newsite1
RewriteCond %{HTTP_HOST} !newsite1 [NC]
# And does not include newsite2
RewriteCond %{HTTP_HOST} !newsite2 [NC]
# Run the routine
RewriteCond %{HTTP_HOST} !^[b]www[/b]\.example\.co[b]m$[/b]
RewriteRule [b](.*)[/b] http://www.example.com/$1 [R=301,L]

Jim