Forum Moderators: phranque

Message Too Old, No Replies

Question about mod rewrite and cpanel subdomains

         

Huijari

2:44 pm on Dec 24, 2009 (gmt 0)

10+ Year Member



Hello, so this is my code:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.site\.net
RewriteCond %{HTTP_HOST} ([^.]+)\.site\.net [NC]
RewriteRule (.*) [site.net...] [P]

It works perfectly, but I have made subdomains in Cpanel too, so if I try to access them, I will get error 404 and url will be: site.net/hosting/site/subdomainsnameincpanel

So, how to create in rewrite thing, that it won't rewrite if url contains word, like "kirppari" (my subdomain)

Thank you a lot.

jdMorgan

6:22 pm on Dec 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a RewriteCond to exclude the subdomains you don't want the rule to handle:

RewriteCond %{HTTP_HOST} !^www\.exmaple\.net
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.net [NC]
[i]RewriteCond %1 !^kirppari$[/i]
RewriteRule (.*) http://www.example.net/hosting/site/%1/$1 [P]

Be aware that you've set up a reverse-proxy here, forcing your server to make HTTP requests from itself. This essentially doubles the number of HTTP requests your server must handle, slows down the user experience, and very likely makes a mess of your access logs and stats as well.

It is more usual to simply rewrite the incoming HTTP to a non-default location in the filesystem using an internal rewrite instead of a proxy through-put. This may not work with your 'cpanel-defined subdomains' but you should try to use it for the others:


RewriteCond %{HTTP_HOST} !^www\.exmaple\.net
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.net [NC]
RewriteCond %1 !^kirppari$
RewriteCond $1 !^hosting/site/[^/]+/
RewriteRule ^(.*)$ hosting/site/%1/$1 [L]

The new RewriteCond is intended to prevent an 'infinite' rewriting loop.
Jim