Domain to Filename Same Directory

Using a single web hosting account to host multiple sites

Domain to Filename Same Directory

Postby omniintegrations » Fri May 04, 2007 7:27 pm

Hi, searched for this one, but not quite sure about how to get it working...

I want all the files in the same directory -

In the root there is index-domain1.html and index-domain2.html
as well as page2-domain1.html and page2-domain2.html
and so on...

so domain1.com would pull up index-domain1.html
and domain2.com would pull up index-domain2.html

Thanks so so so much... this is just not working for me.

Ben

Oh yah, there also is the regular domain that just grabs index.html
so it needs the RewriteCond...
omniintegrations
 
Posts: 3
Joined: Fri May 04, 2007 7:20 pm

Postby omniintegrations » Sun May 06, 2007 12:32 am

Here is the closest I've come... but still... 500 Internal Server Error

Code: Select all
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2)\.com$ [NC]
RewriteRule ^(.*)\.html? %2-$1.html [QSA,L]


So I would think domain2/index.html should bring up domain2/domain2-index.html
omniintegrations
 
Posts: 3
Joined: Fri May 04, 2007 7:20 pm

Postby richardk » Sun May 06, 2007 7:47 am

It's probably looping, try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2)\.com$ [NC]
RewriteRule ^(.*)\.html$ /%2-$1.html [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby omniintegrations » Mon May 07, 2007 2:52 pm

Ha!!! Wow... glad i didn't crash my server... thanks much for pointing that out --- Genious, Genious, Genious!!!!!
omniintegrations
 
Posts: 3
Joined: Fri May 04, 2007 7:20 pm

Similar but diferent

Postby humaneasy » Wed May 23, 2007 6:31 am

My case is similar but not equal.

I have an application in an wildcarded DNS domain and I want that, when people go to a subdomain it:
  1. Strip the www. if it's there
  2. Check the subdomain and convert /custom/config.php in /custom/subdomain/config.php so I don't have to touch the code and could have completely seperated websites.
  3. If there is no subdomain it should use /custom/config.php instead.

Thanks in advance for the help.
humaneasy
 
Posts: 14
Joined: Sat Jul 08, 2006 4:37 pm

Postby richardk » Thu May 24, 2007 1:51 pm

1. Strip the www. if it's there

In a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


2. Check the subdomain and convert /custom/config.php in /custom/subdomain/config.php so I don't have to touch the code and could have completely seperated websites.
3. If there is no subdomain it should use /custom/config.php instead.

Mod_rewrite only works on external requests, it will not change internal PHP includes. I assume that's what's happening?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Oh! Man!

Postby humaneasy » Thu May 24, 2007 2:46 pm

My idea was that when you access http://subdomain.domain.com

The php files there will have an instruction to include a custom config.php file for each subdomain.

As I understood of what you said, the .htaccess instruction will influence the way files are referenced inside an HTML file but not inside a PHP file.

Am I right?

So, I will have to use something like this:
Code: Select all
<?php
    $config = explode(".", $_SERVER [ 'REQUEST_URI' ]);
    if( count($config) == 3)
        $c = $config[0].'/';
    include('/custom/'.$c.'config.php);
?>


Anoying, because upgrades will be more tedious.

Thanks anyway.
humaneasy
 
Posts: 14
Joined: Sat Jul 08, 2006 4:37 pm

Postby richardk » Thu May 24, 2007 2:51 pm

Mod_rewrite works on external requests (from a browser or bot, etc.). When you include() something with PHP it's an file system request (like opening a file on your desktop) so it never goes through Apache or mod_rewrite.

Edit: Put that (or similar) PHP in the main config.php file and then create a separate one for the main domain as well. Your shouldn't have to regularly change the config.php files when you update.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby humaneasy » Thu May 24, 2007 3:33 pm

You're right :)

Thanks!
humaneasy
 
Posts: 14
Joined: Sat Jul 08, 2006 4:37 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 4 guests

cron