How to Redirect web folder through htaccess

How to redirect web folder through htaccess? This question arise to many non-technical people who want to fix self without any plugin. So area wala team will guide you step-by-step.

How to redirect web folder through htaccess?

You can redirect any webpage to required webpage through htaccess. This is very simple, easy and secure. No need any plugin for this. You can do this in easy 3 step.

Total Time: 5 minutes

Step 1: Find htaccess in root redirectory

Simply open file manager of web host. This is lying in root rolder. You can create .htaccess if not present.

Step 2: Open htaccess for edit code

Simply Open htaccess for edit code. You will view some code.

Step 3: Insert redirect code for requirement.

In this case, we have inserted code for redirect folder /top10 to topten. So you can do as per yours requirement.u003cbru003eu003cbru003eWe have written all code below mention and you can do yourself. Comments if you face any problem.

Different code for different purpose

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$ [R=301,L]


Redirect 301 /path/to-old-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 sub-directory to another domain but in the same sub-directory

Redirect 301 /subdirectory

When you need to switch a website from an old domain to a new domain, you need to redirect all your page URLs, this is when htaccess is your friend.

The code below will create 301 url redirects for both the www and non-www version of ‘‘ to the new domain ‘‘.

Add this .htaccess file to the OLD site webroot and upload the files from the old site to the new to see a seamless switch from an old domain to a new one.

So the example below is redirecting all URLs from to, this is also the 301 redirect to use when using Googles Change of Address tool in Search Console.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC,OR]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]

The above will use the non-www as preference.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteRule (.)$1 [R=301,L] RewriteCond %{HTTP_HOST} !^$ RewriteRule (.)$1 [R=301,L]

The above here will redirect 301 all urls from one domain to another but give preference to the www version.

You can also apply this to a subdomain – so the example below is redirecting all URLs from to

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.)$$1 [R=301,L] RewriteCond %{HTTP_HOST} ^$ RewriteRule ^(.)$$1 [R=301,L]

You can also mask a domain which is like a redirect but keeps the old domain URL but shows the remaining part of the new URL of the new domain – example …

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule ^(.*)$1 [P]

Force a Directory Folder or WebSite to go over HTTPS SSL with htaccess

To force a website to use the secure protocol SSL running the whole site over HTTPS you can make a simple edit to the .htaccess file in the document root.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

To force a particular folder or directory to serve over SSL, create a .htaccess file in that folder and apply the following to it:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$$1 [R,L]

This assumes SSL is enabled on the domain on an Apache Web Server with the mod_rewrite module enabled.

Redirecting WWW to non-WWW with htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.)$ [NC] RewriteRule ^(.)$ http://%1/$1 [R=301,L]

You should make sure htaccess file (.htaccess) and place on root folder of website.


You can redirect any web page to required webpage simply from htaccess and need no any technical knowledge for this. Simply fix this problem through .htaccess.

Have you any business?

Post your Business in Fastest Growing Business Directory

Post your classified –

Leave a Comment

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