.htaccess - Apache host with multiple alias/domains rewrite rule -
i have apache vhost server , multiple aliases. server being production/live domain , aliases being dev , staging servers. example:
servername foo.bar serveralias dev.superfoo.bar serveralias stage.superfoo.bar
is there rewrite rule preserve domain, whatever may be, , redirect people domain/en-us/anything domain/en/anything?
i believe ^/en-us/(.*)$ foo.bar/en/1$ trick 1 domain. there way preserve domain instead of writing rule every alias?
to ensure correct domain retained on each one, may use %{http_host}
variable in redirection:
rewriteengine on rewriterule ^/en-us/(.*)$ http://%{http_host}/en/$1 [l,r=301]
the [r=301]
flag issues permanent 301 redirect, in testing may want use 302 since browsers might aggressively cache redirect making hard debug.
above used leading /
in ^/en-us
. necessary if use rule @ virtualhost level. however, if use inside .htaccess file in document root, must not include /
, in:
rewriteengine on rewriterule ^en-us/(.*)$ http://%{http_host}/en/$1 [l,r=301]
the rules around noted in "what matched" section of rewriterule
manual.
Comments
Post a Comment