Use Mod_Rewrite to Rewrite ROOT to Another Path Use Mod_Rewrite to Rewrite ROOT to Another Path apache apache

Use Mod_Rewrite to Rewrite ROOT to Another Path


A correct redirect of the root path is simply :

RewriteEngine OnRewriteRule ^/$ /page [R]

to force this only on one subdomain (which should barely happen if your rewrite block is in a virtualhost definition) :

RewriteEngine onRewriteCond %{HTTP_HOST} =subdomain.example.comRewriteRule ^/$ /page [R]


Copying my deleted response:

In htaccess of your documentroot simply:

RewriteEngine onRewriteCond %{HTTP_HOST} =subdomain.example.comRewriteRule ^$ /page


You have two options to rewrite your root to another path,

  1. DirectoryIndex:

    DirectoryIndex anotherPath
  2. Mod-rewrite:

    RewriteEngine onRewriteRule ^/?$ /anotherPath [L]

You can use one of the above options to internally redirect example.com/ to example.com/anotherPath.

References:

  1. https://httpd.apache.org/docs/current/mod/mod_dir.html
  2. http://httpd.apache.org/docs/current/mod/mod_rewrite.html