Jump to content

How to Rewrite Domains to folders, by apache mod_rewrite?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
eurusd

eurusd

    Newbie

  • Members
  • Pip
  • 9 posts
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!

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
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.

#3
jhonichen

jhonichen

    Newbie

  • Members
  • PipPip
  • 20 posts
I think it is about creating virtual host on apache:

<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"];