LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-22-2010, 07:02 AM   #1
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 787
Blog Entries: 6

Rep: Reputation: 75
sub domain rewrite code


Hi guys, is there a way for me to make it work with apache rewrite code in (httpd.conf apache2 centos5.5)

example1: mkdir /home/dom1.com/user1 <- this will go to http://user1.dom1.com

example2: mkdir /home/dom2.com/user1 <- this will go to http://user1.dom2.com

FYI dns wild card already done

thanks

regards

Routers
 
Old 10-22-2010, 07:45 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

I guess that by wildcard dns you mean *.dom1.com and *.dom2.com.
In that case why do you need the rewrite? You can setup the DocumentRoot for each vhost to be the desired one and add a ServerAlias for each, e.g for dom1.com:
<VirtualHost :80>
ServerName dom1.com
ServerAlias *.dom1.com
DocumentRoot /home/dom1.com/user1
...
</VirtualHost>
If that's not what you want to do, please elaborate.

Regards
 
Old 10-22-2010, 08:04 AM   #3
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 787

Original Poster
Blog Entries: 6

Rep: Reputation: 75
yeah the wildcard way is right the main issue is i have 40 staff
i want to give 30 of them to do thier own web site just to show my boss i can do something

since that of 30 staff need 30 sub domain so i dont want to add VirtualHost for each
what i want is simple i create /home/dom1.com/staff1 so that staff will have http://staff1.dom1.com

also if the staff1 need to use second domain i will create /home/dom2.com/staff1 and this will go to http://staff1.dom2.com

then i will copy all the file given to me my self to thier own folder
this should work w/o restarting apache

hope i can get some good info about this

thanks
 
Old 10-22-2010, 08:19 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
You should have use something like staff1.domain.com, staff2.domain.com and so on, in which case mod_rewrite can be used.
If you want to have 30 domains (dom1.com, dom2.com ...), then you'll also need 30 vhosts
 
Old 10-22-2010, 09:04 AM   #5
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 787

Original Poster
Blog Entries: 6

Rep: Reputation: 75
i found this scripts code but could not make it work

look promising for me but not worked

http://tips-scripts.com/subdomains
 
Old 10-22-2010, 12:33 PM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

The rewrite code in the link you've posted works for subdomains. Meaning you have one domain configured as wildcard in apache and you use rewrite to serve different pages depending on the subdomain requested.
I've already told you that this can be done with mod_rewrite.

But, you don't want to use subdomains, rather than different domains (dom1.com, dom2.com etc) with the same hostname (staff1.dom1.com, staff1.dom2.com ...). This involves that apache must be configured to serve these domains (meaning several vhosts).
 
Old 10-22-2010, 01:23 PM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi again,

After thinking a bit more I think it's can be done using a little hack with the apache default vhost.
Assuming that staff1.domX.com points to the IP of your apache server, you'll need the following settings:

1. You don't define any vhost, so the request for staff1.domX.com will point to the default apache DocumentRoot
2. The DocumentRoot should be /home in your case

That said you can use this in .htaccess:
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^staff1.(dom[0-9]+).com$
RewriteCond %{REQUEST_URI} !^/dom
RewriteRule (.*) /%1.com/staff1 [L]
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any benefit to rewrite OSS-based code to ALSA-based code? RogueWarrior65 Linux - Software 1 08-13-2010 02:11 AM
Postfix Rewrite Destination Domain Name? doctorcisco Linux - Server 2 11-03-2007 11:02 AM
Top-Level Domain rewrite using mod_rewrite in Apache2 subcon Linux - Server 0 06-24-2007 11:33 PM
Apache 2 Rewrite One Domain To Another thunder04 Linux - Software 10 04-19-2006 01:38 AM
need a mail relay that rewrite the sender's domain linuxboy123 Linux - Networking 3 04-20-2005 03:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration