vijay.shad
vijay.shad

Reputation: 2474

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 translated 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?

Upvotes: 1

Views: 128

Answers (1)

Fire Crow
Fire Crow

Reputation: 7729

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} ...

Upvotes: 4

Related Questions