Page 1 of 1

How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 6:06 pm
by eurusd
How to Rewrite Domains to folders, by apache mod_rewrite?
I have got many domains like this:
Mybestdomain.com
Londondomen.co.uk
Primedomainame.info
Promotion.television.org
Blogging.mysite.com
News.freedomains.co.uk
Tv.news.blogging.net
Internet.news.blogging.net
….
Etc…..
They are all pointing to one ip and to one folder
/home/www/allinone/
All these domains take many files from folder
/home/www/allinone/oftenusedfiles/
/home/www/allinone/oftenusedfiles2/
/home/www/allinone/oftenusedfiles3/
/home/www/allinone/usedfilesabc/
and from /home/www/allinone
$root= _SERVER["DOCUMENT_ROOT"];

by include ( $root.”/ oftenusedfiles/usedfunction.inc”);
…… etc ………..



How to do this:
When I enter domain in my browser lets say
http://Mybestdomain.com/ it shows http://Mybestdomain.com/ but goes to
/home/www/allinone/ Mybestdomain.com
Or when I enter domains in my browser for example:
http:// Londondomen.co.uk
it shows same URL but fetches data from Londondomen.co.uk
Basically like this domain name becomes a folder with according name

http://%{HOST_NAME}/ --------- /home/www/allinone/%{HOST_NAME}/

http://%{HOST_NAME}/script.php?show=45 --------- /home/www/allinone/%{HOST_NAME}/script.php?show=45

http://%{HOST_NAME}/%{REQUEST_URI%{QUERY_STRING} --------- /home/www/allinone/%{HOST_NAME}/%{REQUEST_URI}%{QUERY_STRING}


http:// Blogging.mysite.com gets data from /home/www/allinone/ Blogging.mysite.com/
http:// Promotion.television.org gets data from /home/www/allinone/ Promotion.television.org/
….
/home/www/allinone/ Londondomen.co.uk/
/home/www/allinone/ News.freedomains.co.uk/
/home/www/allinone/ Internet.news.blogging.net/

Tried all I could nothing works, I really don’t understand reg exp and rewrite

RewriteCond %{HTTP_HOST} ^(.+)$

RewriteRule (.+) /%{HTTP_HOST}/ [QSA,L]

RewriteRule /%{HTTP_HOST}/%{REQUEST_URI} [QSA,L]


Etc…

THANK YOU FOR YOUR HELP!

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 6:58 pm
by requinix
How is this all set up? Because I'm sure you can be doing it differently.

Like with VirtualHosts.

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 7:56 pm
by eurusd
what do you mean vhosts?

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 8:36 pm
by requinix
Uh huh. Explains a lot.

You can have Apache serve up multiple websites on one machine: VirtualHosts is how.

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 9:35 pm
by eurusd
but i want one document root for all of them

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 10:42 pm
by requinix
Not according to your first post. Each site has a different document root.

If they don't then why are you trying to get a RewriteRule to accomplish just that?

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 10:49 pm
by eurusd
you dont read carefully

and from /home/www/allinone
$root= _SERVER["DOCUMENT_ROOT"];
$root for everyone of these domains is the same /home/www/allinone/

all i am asking is the simple question
how do you rewrite {DOMAINNAME} to get data from $ROOT/{DOMAINNAME}/

it is a very simple questions for those who know mod rewrite

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sat May 02, 2009 11:00 pm
by requinix
eurusd wrote:How to do this:
When I enter domain in my browser lets say
http://Mybestdomain.com/ it shows http://Mybestdomain.com/ but goes to
/home/www/allinone/ Mybestdomain.com
Or when I enter domains in my browser for example:
http:// Londondomen.co.uk
it shows same URL but fetches data from Londondomen.co.uk
Funny, I read that to mean
How do I make each of these sites serve out of a different directory?
Which is exactly what VirtualHosts can do.

Stop trying to do what you think is right and start looking for a solution to your real problem.

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sun May 03, 2009 11:03 am
by eurusd
jesus :)

all i am asking forget virtualhosts forget everything
just tell me how via .htaccess rewrite

rewrite any domain to its folder?
it is probably two lines code...

probably what i am asking is too difficult for you and you try to solve the problem by suggesting me virtualhosts
i did not ask you about virtualhosts, i asked about rewrite

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sun May 03, 2009 1:30 pm
by ldougherty
Hello, a simple example I've used for our customers in the past for rewriting traffic from a subdomain to a subfolder. Say you have test.domain.com and you want it to read from domain.com/test

Create a .htaccess file in your web root with the below information or place this information in your httpd.conf file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.domain.com$
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^(.*)$ /test/$1

Hope this helps out.

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sun May 03, 2009 1:44 pm
by eurusd
thank you very much,ldougherty, you are the only one who understands something :lol: !
found extra examples, might be useful from http://forum.powweb.com/showthread.php?t=73248

and now I use like this:

RewriteBase /
RewriteCond %{HTTP_HOST} ^%{HTTP_HOST}$ [NC,OR]
RewriteCond %{REQUEST_URI} !/%{HTTP_HOST}/
RewriteRule ^(.*)$ /home/ftproot/blockofwebsites/%{HTTP_HOST}/$1 [L]


without RewriteCond %{REQUEST_URI} !/%{HTTP_HOST}/
i went into loops and apache says exceeded maximum redirects
although i could see in error.log with debuglevel rewrite 9 that it does loops but could not understand why it did so
domain name was multiplied many times and translated into REQUEST_URI
now any domain can be translated to its sub folder, that's what i wanted

thanks!

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sun May 03, 2009 2:14 pm
by ldougherty
No problem, glad I could help out.

Re: How to Rewrite Domains to folders, by apache mod_rewrite?

Posted: Sun May 03, 2009 2:38 pm
by eurusd
sure you did, appreciate effort ;) :drunk: