8 domains/websites, 1 hosting account, and friendly URL's ..

Using a single web hosting account to host multiple sites

8 domains/websites, 1 hosting account, and friendly URL's ..

Postby cypherbud » Wed Aug 01, 2007 4:55 pm

So I finally found this website after searching for mod_rewrite coding, asking around, etc.

I have used mod_rewrite to create friendly URL's for just one of my websites. It's a nice, clean way to organize thousands of "pages", when they're actually fields in my database.

In addition to the dynamic friendly URL's I created, there are a few template, css, etc files in a few static folders throughout my site.

I accidentally created a mess when I switched to go daddy (godaddy.com) on the lowest hosting account, which allows 1 hosted domain plus email accounts and all that jazz ... but allows you to alias other domains to the one hosted account. Sounds fine and dandy if you have a search portal with pop-up downloaders and a whole bunch of the same stuff ... but I have 8 domains, 8 seperate websites. I found the code after searching for weeks, thanks to Richardk on this forum.

-------------
Currently, I have a few php files routing the main portions of my website (example: /contact, /products, /services). Using just one php file for all 8 of my domains, could someone help me write a mod_rewrite script that will accomplish the following, dynamically:

* Point domains I have put into an array somewhere (preferably in the htaccess file itself) to their proper folder
*look for static folders
* If no static folder found, look for dynamic via my mod_rewrite code

Hosted domain = hosted.com
Alias domain 2 = alias2.com
Alias domain 3 = alias3.com
Alias domain 4 = alias4.com
Alias domain 5 = alias5.com
Alias domain 6 = alias6.com
Alias domain 7 = alias7.com
Alias domain 8 = alias8.com

Feel free to edit my previous code, it's working, but it's also patch-work code...

--------------------------------------------------
ErrorDocument 404 %{HTTP_HOST}/?

Options +FollowSymLinks

RewriteEngine On

# Previous working mod_rewrite for alias8.com
RewriteRule ^gallery/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([.A-Za-z0-9-]+)/?$ /templates/gallery/router.php?passed_venue_name=$1&passed_venue_section=$2&passed_venue_other=$3 [N]
RewriteRule ^gallery/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /templates/gallery/router.php?passed_venue_name=$1&passed_venue_section=$2 [N]
RewriteRule ^gallery/([A-Za-z0-9-]+)/?$ /templates/gallery/router.php?passed_venue_name=$1 [N]
RewriteRule ^gallery/?$ /templates/gallery/router.php? [L]

--------------------------------------------

# Code, compliments of richardk via modrewrite.com's forums
# Points alias8.com to a folder on my hosted.com domain
# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?alias8\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/alias8%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Domain to sub directory.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?alias8\.com$ [NC]
RewriteRule ^(.*)$ /alias8/$1 [QSA,L]

--------------------------------------------

So to summarize what I'm trying to do here ...

1)
I would like each of the alias domains to point to a sub folder on the hosted domain.

2)
I would love a simple solution suggestion ... as far as adding another domain quickly, and preferably static.

3)
I would like mod_rewrite to try and find a physical folder on the server. If it doesn't exist, then look to a template php script file for direction. Currently, I have a maximum of 5 folders from the root of the domain ... not including the hosted.com/alias8/ folder

4)
In addition to creating friendly folders dynamically, the files should work too ... but they would only be images, movies, a few php files with template includes and such, etc. I can add to a list of file formats if it's necessary to add mime types in this code.

----------------------------

Thanks for your time ... it seems like a lot to ask, especially all at once.

Sean Francis[/list]
cypherbud
 
Posts: 4
Joined: Sat Jul 28, 2007 3:07 pm

Postby richardk » Sat Aug 04, 2007 12:28 pm

So you would be OK with this?
Code: Select all
domain-one.com/* to the /domain-one.com/* sub directory and
domain-two.com/* to /domain-two.com/* and
domain-three.net/* to /domain-three.net/* etc.


Then you could use
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(.+)$
RewriteCond %{DOCUMENT_ROOT}/%1/ -d
RewriteRule ^(.*)$ /%1/$1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(.+)$
RewriteCond %{DOCUMENT_ROOT}/%1/ !-d
RewriteRule ^(.*)$ /handler.php?domain=%1&path=/$1 [QSA,L]

You don't have to change it if you add new domains (just create the directory), everything gets rewritten to the sub directory and if the directory doesn't exist it goes to handler.php. Any mod_rewrite for the domains would go in their sub directory.

For the gallery mod_rewrite
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^gallery/([a-z0-9-]+)/([a-z0-9-]+)/(.*[^/])/?$ /templates/gallery/router.php?passed_venue_name=$1&passed_venue_section=$2&passed_venue_other=$3 [NC,L]
RewriteRule ^gallery/([a-z0-9-]+)/([a-z0-9-]+)/?$ /templates/gallery/router.php?passed_venue_name=$1&passed_venue_section=$2 [NC,L]
RewriteRule ^gallery/([a-z0-9-]+)/?$ /templates/gallery/router.php?passed_venue_name=$1 [NC,L]
RewriteRule ^gallery/?$ /templates/gallery/router.php [NC,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 116 guests

cron