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?
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
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]
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With