Reputation: 1924
I was just wondering how to perform a redirect from root in Apache.
I want to check if someone goes to the root url (eg. example.com
) and redirect them to example.com/h
automatically.
Can I do this in apache config, or in a .htaccess
file?
Upvotes: 5
Views: 582
Reputation: 61
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
RedirectMatch 301 ^/$ /h
</VirtualHost>
This will help you to redirect all your request from example.com
to example.com/h
Upvotes: 5
Reputation: 785146
You can use this mod_rewrite
rule in Apache config or in root .htaccess:
RewriteEngine On
RewriteRule ^/?$ /h [L,R=302]
Change R=302
to R=301
after verifying this redirect rule. If you don't want the URL in the browser to change then use:
RewriteRule ^/?$ /h [L]
Upvotes: 2
Reputation: 45829
You can do this in either Apache config or .htaccess (per directory config files).
Using mod_rewrite in .htaccess, to redirect from the root to a specific URL:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^$ /h [R,L]
Note that this is a temporary (302) redirect.
Upvotes: 0