Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache redirect from root

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?

like image 230
Jo Colina Avatar asked Jul 30 '15 10:07

Jo Colina


2 Answers

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

like image 165
Suriyanarayanan Avatar answered Sep 27 '22 02:09

Suriyanarayanan


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]
like image 23
anubhava Avatar answered Sep 23 '22 02:09

anubhava