• Skip to primary navigation
  • Skip to main content

Javier Lona

Web Developer in Texas

  • Home
  • Blog
  • Projects
  • Email
  • GitHub
  • LinkedIn
  • Twitter
  • YouTube

How to redirect from a sub-folder to a deeper sub-folder

Learn how to redirect your visitors to a sub-folder that’s two levels deep from the root directory.

August 1, 2018 by Javier

Learn how to redirect your visitors to a sub-folder that’s two levels deep from the root directory.

For example www.RootDir.com/SubFolderA/SubFolderB.

Let’s say users arrive at SubFolderA and you want to redirect them to SubFolderB.

.htaccess code

RedirectMatch ^/SubFolderA/?$ /SubFolderA/SubFolderB/

Place the .htaccess file with the above line in the root directory of the domain.

What Does it Mean?

Apache provides two modules for redirecting stuff with .htaccess: mod_alias and mod_rewrite. RedirectMatch falls under the module mod_alias.

  • ^ Denotes the beginning of a regular expression
  • $ Denotes the end of a regular expression
  • ? Declares the preceding character “/” (forward slash) is optional

Category iconGuide Tag iconApache,  Linux