mod rewrite - How do I use .htaccess to redirect to a URL containing HTTP_HOST? -
problem
i need redirect short convenience urls longer actual urls. site in question uses set of subdomains identify set of development or live versions.
i url requests redirected include http_host such don't have create custom .htaccess file each host.
host-specific example (snipped .htaccess file)
redirect /terms http://support.dev01.example.com/articles/terms/
this example works fine development version running @ dev01.example.com. if use same line in main .htaccess file development version running under dev02.example.com i'd end being redirected wrong place.
ideal rule (not sure of correct syntax)
redirect /terms http://support.{http_host}/articles/terms/
this rule not work , merely serves example of i'd achieve. use exact same rule under many different hosts , correct result.
answers?
- can done mod_alias or require more complex mod_rewrite?
- how can achieved using mod_alias or mod_rewrite? i'd prefer mod_alias solution if possible.
clarifications
i'm not staying on same server. i'd like:
- http://example.com/terms/ -> http://support.example.com/articles/terms/
- https://secure.example.com/terms/ -> http://support.example.com/articles/terms/
- http://dev.example.com/terms/ -> http://support.dev.example.com/articles/terms/
- https://secure.dev.example.com/terms/ -> http://support.dev.example.com/articles/terms/
i'd able use same rule in .htaccess file on both example.com , dev.example.com. in situation i'd need able refer http_host variable rather specifying literally in url requests redirected.
i'll investigate http_host parameter suggested hoping working example.
it's strange nobody has done actual working answer (lol):
rewritecond %{http_host} support\.(([^\.]+))\.example\.com rewriterule ^/terms http://support.%1/article/terms [nc,qsa,r]
to doing job faster, favorite tool check regexp:
http://www.quanetic.com/regex (don't forget choose ereg(posix) instead of preg(pcre)!)
you use tool when want check url , see if they're valid or not.
Comments
Post a Comment