How to Rewrite Domains to folders, by apache mod_rewrite?
Moderator: General Moderators
How to Rewrite Domains to folders, by apache mod_rewrite?
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!
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?
How is this all set up? Because I'm sure you can be doing it differently.
Like with VirtualHosts.
Like with VirtualHosts.
Re: How to Rewrite Domains to folders, by apache mod_rewrite?
what do you mean vhosts?
Re: How to Rewrite Domains to folders, by apache mod_rewrite?
Uh huh. Explains a lot.
You can have Apache serve up multiple websites on one machine: VirtualHosts is how.
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?
but i want one document root for all of them
Re: How to Rewrite Domains to folders, by apache mod_rewrite?
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?
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?
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
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?
Funny, I read that to meaneurusd 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
Which is exactly what VirtualHosts can do.How do I make each of these sites serve out of a different directory?
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?
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
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
-
ldougherty
- Forum Contributor
- Posts: 103
- Joined: Sun May 03, 2009 11:39 am
Re: How to Rewrite Domains to folders, by apache mod_rewrite?
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.
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?
thank you very much,ldougherty, you are the only one who understands something
!
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!
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!
-
ldougherty
- Forum Contributor
- Posts: 103
- Joined: Sun May 03, 2009 11:39 am
Re: How to Rewrite Domains to folders, by apache mod_rewrite?
No problem, glad I could help out.
Re: How to Rewrite Domains to folders, by apache mod_rewrite?
sure you did, appreciate effort
