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
hxxp://Mybestdomain.com/ it shows hxxp://Mybestdomain.com/ but goes to
/home/www/allinone/ Mybestdomain.com
Or when I enter domains in my browser for example:
hxxp:// 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
hxxp://%{HOST_NAME}/ --------- /home/www/allinone/%{HOST_NAME}/
hxxp://%{HOST_NAME}/script.php?show=45 --------- /home/www/allinone/%{HOST_NAME}/script.php?show=45
hxxp://%{HOST_NAME}/%{REQUEST_URI%{QUERY_STRING} --------- /home/www/allinone/%{HOST_NAME}/%{REQUEST_URI}%{QUERY_STRING}
hxxp:// Blogging.mysite.com gets data from /home/www/allinone/ Blogging.mysite.com/
hxxp:// 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!
How to Rewrite Domains to folders, by apache mod_rewrite?
Started by eurusd, May 02 2009 03:08 PM
2 replies to this topic
#1
Posted 02 May 2009 - 03:08 PM
|
|
|
#2
Posted 02 May 2009 - 03:37 PM
Posted via CodeCall Mobile
another way is to do this in php by doing a string rewrite on hostname in url called and include the index.php in wished directory.
another way is to do this in php by doing a string rewrite on hostname in url called and include the index.php in wished directory.
#3
Posted 11 May 2009 - 07:31 AM
I think it is about creating virtual host on apache:
or
create only 1 virtual host with many server alias and put every request run a php file
<VirtualHost *:80> DocumentRoot /home/www/allinone/oftenusedfiles ServerName Mybestdomain[dot]com <Directory /home/www/allinone/oftenusedfiles> Options All Order allow,deny Allow from all </Directory> ErrorLog /home/www/allinone/oftenusedfiles/error_log.txt </VirtualHost>and duplicate above config for other sites by changing the directory name
or
create only 1 virtual host with many server alias and put every request run a php file
<VirtualHost *:80>
DocumentRoot /home/www/allinone
ServerName Mybestdomain[dot]com
ServerAlias Mybestdomain1[dot]com
ServerAlias Mybestdomain2[dot]com
<Directory /home/www/allinone>
Options All
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) refolder.php
</Directory>
ErrorLog /home/www/allinone/error_log.txt
</VirtualHost>
and put these code on refolder:
$basePath = dirname(__FILE__);
switch($_SERVER["SERVER_NAME"]) {
case "www[dot]allinone1[dot]com":$basePath.="/allinone1";break;
case "www[dot]allinone2[dot]com":$basePath.="/allinone2";break;
case "www[dot]allinone3[dot]com":$basePath.="/allinone3";break;
default: $basePath.="/allinone";break;
}
include($basePath."/parserequest.php");
and do the url parsing to include the correct file on parserequest.php using $_SERVER["REQUEST_URI"];


Sign In
Create Account

Back to top









