.htaccess to Redirect from sub folder to root

.htaccess to Redirect from sub folder to root
Redirection | TechniqZone

.htaccess files used to make configuration changes on a per-directory basis. we can Redirect direct web site visitors from one document within your web site to another using .htaccess file.


Redirect /old_dir/ http://www.domain.com/new_dir/index.html

The above line tells the Apache Web Server that if a visitor requests a documents located in the directory ‘old_dir’, then to display the document ‘index.html’ located in the directory ‘new_dir’.

If you want to redirect all the pages inside from one folder, consider as demo, to root folder i.e.,public_html,

RewriteEngine on
RewriteRule ^demo/(.*)$  /$1 [R=301,L]

and .htaccess file should be placed inside root folder i.e.,public_html

Or You can place you .htaccess inside folder (demo folder) with below changes

RewriteEngine On
RewriteRule ^(.*)$  /$1 [R=301,L]

Leave a Reply

Your email address will not be published. Required fields are marked *