Simple Mod_Rewrite Help!
June 19, 2009 5:56 PM

I need help with a simple mod_rewrite!

I have some domains in Cpanel. I'll call them domain1.com, domain2.com and domain3.com.

I want all 3 of these domains to be redirected/have their doc root set as /public_html/myfolder/

Easy enough for domains 2 and 3, since they are addons, and I can set where their root is. But domain 1 is the main domain, and its root is set as /public_html/

What mod_rewrite can I use to ensure that domain1.com is redirected to the /myfolder under public_html?

Also, as an added bonus, /myfolder has various subfolders on it, so domain2.com/abba is the same as domain3.com/abba, because of how their roots are set. I need to ensure that domain1.com/abba will actually go to that folder through the mod_rewrite.

Thank you so much in advance!!
posted by omnipotentq to Computers & Internet (5 answers total)
RewriteRule ! ^/public_html/myfolder(.*) /public_html/myfolder$1
posted by sbutler at 6:26 PM on June 19, 2009


Hm. That seems to just give a server misconfiguration error.
posted by omnipotentq at 6:34 PM on June 19, 2009


Well, my mod_rewrite is a little rusty :)
posted by sbutler at 6:37 PM on June 19, 2009


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


I found that at another site, and it did the trick!
posted by omnipotentq at 7:15 PM on June 19, 2009


If you want to keep it at the same domain without the 301 redirect, I think it's—building on sbutler's answer—this:
# Prevents infinite recursion.
RewriteCond %{REQUEST_URI} !^/public_html/myfolder [NC]
RewriteRule ^(.*)$  public_html/myfolder/$1 [NC, L]

posted by shadytrees at 7:39 PM on June 19, 2009


« Older Mammogram vs ultrasound   |   God as a jerk boss Newer »
This thread is closed to new comments.