Problem - name.domain.com rewrite to domain.com/id

Using a single web hosting account to host multiple sites

Problem - name.domain.com rewrite to domain.com/id

Postby webtesterer » Thu Jul 24, 2008 5:49 pm

Hello, I have a blog script that make each user a directory such as
http://www.example.com/20
http://www.example.com/21

and I have a map.txt
Code: Select all
jim 20
tom 21


I use this to rewrite http://abc.example.com to http://example.com/abc/
how can I modify this to rewrite http://jim.example.com to http://example.com/20 ?
Any help appreciated ^_^

Code: Select all
Options +FollowSymLinks
RewriteEngine On

# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /%2/$1 [QSA,L]
webtesterer
 
Posts: 8
Joined: Thu Jul 24, 2008 4:55 pm

Postby richardk » Fri Jul 25, 2008 3:20 pm

In your <VirtualHost>
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteMap user_to_id txt:/path/to/map.txt

# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteCond ${user_to_id:%2} ^([0-9]+)$
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteCond ${user_to_id:%2} ^([0-9]+)$
RewriteRule ^(.*)$ /%1/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby webtesterer » Fri Jul 25, 2008 6:40 pm

it works! thank you ! :D :D
webtesterer
 
Posts: 8
Joined: Thu Jul 24, 2008 4:55 pm

Postby webtesterer » Sun Aug 17, 2008 11:53 pm

Hello richardk :P :P
How to modify it to rewrite
http://abc.example.com/help/
==>
http://www.example.com/help/
but not affect other mappings ? thx
webtesterer
 
Posts: 8
Joined: Thu Jul 24, 2008 4:55 pm

Postby richardk » Mon Aug 18, 2008 4:49 pm

You mean just for /help? Try adding
Code: Select all
RewriteRule ^help/?$ - [L]

after
Code: Select all
RewriteMap user_to_id txt:/path/to/map.txt
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby webtesterer » Thu Aug 21, 2008 9:21 pm

richardk wrote:You mean just for /help? Try adding
Code: Select all
RewriteRule ^help/?$ - [L]

after
Code: Select all
RewriteMap user_to_id txt:/path/to/map.txt


Thank you richardk :P Yes, just for /help .

I tried it but when I type in
http://tom.example.com/help/index.html
still response 404 error.
(http://tom.example.com/images/logo.gif is ok, it's rewrited to http://www.example.com/21/images/logo.gif)

I do have
http://www.example.com/help/index.html

all rules are copy from above and not changed .
Can you have a look, thanks :wink:
webtesterer
 
Posts: 8
Joined: Thu Jul 24, 2008 4:55 pm

Postby richardk » Sat Aug 23, 2008 9:47 am

Replace
Code: Select all
^help/?$

(which only matches /help or /help/) with
Code: Select all
^help(/.*)?$

(which matches /help or /help/anything).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby webtesterer » Sun Aug 24, 2008 9:35 pm

richardk wrote:Replace
Code: Select all
^help/?$

(which only matches /help or /help/) with
Code: Select all
^help(/.*)?$

(which matches /help or /help/anything).


still returns 404, maybe the following rules overwrite it ?
webtesterer
 
Posts: 8
Joined: Thu Jul 24, 2008 4:55 pm

Postby richardk » Tue Aug 26, 2008 10:56 am

Doh, it's a <VirtualHost>, try
Code: Select all
^/help(/.*)?$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby webtesterer » Thu Aug 28, 2008 1:10 am

OK now! richardk you are genius! :P
webtesterer
 
Posts: 8
Joined: Thu Jul 24, 2008 4:55 pm

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 2 guests

cron