Htaccess Logic

Redirecting a Web Folder Directory to another Directory in .htaccess

Redirecting within the same domain

Using htaccess in your root level of your web server, how you redirect one page to another is:

  • RewriteRule ^url-string-to-redirect$ https://www.linuxguru.co.in/your-new-url-string [R=301,L]

Or

  • Redirect 301 /path/to-old-url https://www.linuxguru.co.in/path/to-new-url

Or

  • Redirect / https://www.linuxguru.co.in/path/to-new-url

To redirect the contents of a whole directory to another use the below:

  • RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L]

To redirect the contents of a whole directory to the webserving root:

  • RewriteRule ^subdirectory/(.*)$ /$1 [R=301,NC,L]

To redirect the contents of a subdirectory to another domain but in the same subdirectory

  • ┬áRedirect 301 /subdirectory http://www.anotherdomain.com/subdirectory

Make sure that the opening of the .htaccess file contains the 2 lines of code below which enables the Apache module to rewrite the URLS, then place your redirections below them

Options +FollowSymLinks
RewriteEngine On