.htaccesshttp-redirectmod-alias

.HTACCESS Redirect 301 all files from root directory to sub directory


I am trying to redirect the user accessing my web root directory to a sub directory.

I am trying this:

//301 Redirect Entire Directory

RedirectMatch 301 /(.*) /1.0/projects/navigator/$1

However, it doesnt work, but repeats the path of the sub directory several times:

[my_domain]/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/1.0/projects/navigator/

How to do this?

Thanks in advance


Solution

  • Put the follwoing code at root directory .htaccess file

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/1.0/projects/navigator/
    # the above line will exclude the same sub directory from the rule below so
    # no looping as what happened with you 
    RewriteRule ^(.*)$ /1.0/projects/navigator/$1 [R=301,L]