The Apache HTTP Server's mod_alias
provides the Redirect
directive which is great for simple redirects, like the following:
# Redirect login to https
Redirect permanent /login https://www.example.org/login
While many admins use mod_rewrite
for redirects, the Apache documentation at When not to use mod_rewrite suggest that in general, mod_alias
is preferred over mod_rewrite
. I'd like to use mod_alias
more.
Can I use Redirect
with Apache variables such as ServerName
? For example, to enforce that certain content is available over HTTPS only, I would want to do something like this:
Redirect permanent /login https://%{SERVER_NAME}/login
Redirect permanent /special-project-1 https://%{SERVER_NAME}/special-project-1
Redirect permanent /special-project-2 https://%{SERVER_NAME}/special-project-2
Neither of these work, and the literal string %{SERVER_NAME}
is printed in the response:
host% curl http://www.example.org/login
...
302 Found
The document has moved <a href="https://%{SERVER_NAME}/login">here</a>.
Are Apache variables allowed with mod_alias
directives? Are the variables available using a different syntax?