RewriteMap frustration

Using a single web hosting account to host multiple sites

RewriteMap frustration

Postby SID » Sat Jan 22, 2005 6:26 pm

Can anyone help with following please:
I have *wildcard DNS enabled & access to httpd.conf
I wish to do the following using RewriteMap with .txt file named s2t.txt
on a per virtual host basis: to take a "subdomain" portion of a domain(sub.domain.com)
or(www.sub.domain.com)and 301 redirect it to an external site/domain or if it does
not exist in the s2t.txt file "goto local" index.php. Must be able to use www. or no www.
and redirect with 301 status.

I would like for the s2t.txt file to be in the format:
subdomain target
a few example lines being:

mysub1 http://mysite1.com
mysub2 http://mysite2.com
mysub3 http://mysite3.com

etc
etc

I have spent days over this and got nowhere and I am getting more & more confused the more
I read and so finally I am requesting the easy way out if anyone would care to step in and help.
I am not sure if when the .conf part is done that I have to have .htaccess also? or if apache
has to be stopped & restarted every time a new entry is placed in the txt file.
Hope someone out there can help.

Thanks to anyone in advance.
SID
 
Posts: 2
Joined: Sat Jan 22, 2005 9:36 am

RewriteMap force external redirect if subdomains exsist

Postby Caterham » Tue Jan 25, 2005 7:05 am

httpd.conf: virtual host context or server config context wrote:
Code: Select all
RewriteEngine on
#   specify the RewriteMap file with the full physical unix path
#   RewriteMap might not work on Windows systems, see apache manual
RewriteMap user-subdomain txt:/var/www/apache/user-subdomain.txt
#   exit, if index.php from the doc root was called
RewriteRule ^/index\.php - [L]
#   domain must not be www.domain.com or www.domain.com:80
RewriteCond %{HTTP_HOST} !^www\.[^.]+\.[a-z]{2,}(:[0-9]+)?$
#   domain is www.sub1.domain.com or sub1.domain.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.[^.]+\.[^.]{2,}
#   for every request get the subdomain from the rewrite map (%2 backreference
#   contains the name of the submain (sub1) from the last RWCondition) or
#   use the index.php if the subdomain is not specifyed in the rewrite map
#   and force an external redirect and last rule (prcessing ends)
RewriteRule ^.* ${user-subdomain:%2|http://standarddomain.com/index.php} [R=301,L]


Robert
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Thank you for the help...

Postby guest » Sat Mar 26, 2005 3:12 pm

That was what I was looking for too. And it works!
Thank you so much! :D
guest
 

Re: Thank you for the help...

Postby RolfKramer » Sat Mar 26, 2005 3:15 pm

guest wrote:That was what I was looking for too. And it works!
Thank you so much! :D
RolfKramer
 


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 103 guests

cron