How to do URL rewriting
I am very new to httpd server. And i have a immediate problem to solve. My server instance is running on centos box.
If a request comes to my server as
http://sub-domain.domain.com
This should be transla开发者_高级运维ted to
http://domain.com/key/sub-domain
I have configured many virtual host on my server. But this is quite a case and i am running out of ideas
Any suggestion: what should i do?
if your using apache
ServerName sub-domain.domain.com
RedirectMatch /(.*) http://domain.com/key/sub-domain/$1
thus
http://sub-domain.domain.com/a-page-i-want-to-see.html
will send a 301 redirect to
http://domain.com/key/sub-domain/a-page-i-want-to-see.html
if you need to dynamically detect the sub-domain, you may need some additional settings.
RewriteCond %{HTTP_HOST} is what you need, but I'm not sure about the specifics of how it works, you may need to use.
I did find the wildcard serverAlais for all the subdomains though.
ServerName domain.com
ServerAlias *.example.com
RewriteCond %{HTTP_HOST} ...
精彩评论