Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

mod rewrite - Pointing a subdomain to a subfolder using .htaccess

My webhost automatically forwards all requests to *.mydomain.com to the toplevel domain mydomain.com.

I wanted to map any subdomain to a specific folder on my toplevel domain. i.e. sub.example.com must be mapped to example.com/someFolder (without change in the address bar).

After digging around on the net, I came up with this:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?[^.]+.example.com.*$
RewriteRule (.*) http://example.com/myfolder/$1 [L]

This seems to work well, except for one problem: When I go to the URL sub.example.com, the URL in the address bar changes to example.com/myfolder . But, when I do something like sub.example.com/login - this maps to "example.com/sub/login" properly without the change in the address bar. Any help greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

only small change needed:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?[^.]+.example.com.*$
RewriteRule (.*) myfolder/$1 [L]

stripped out http:// at the rule which tells Apache to send a Redirect header instead of proper server-side rewrite.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...