301 Redirect in htaccess

How to setup 301 Redirect in .htaccess file?

301 Redirect in htaccess

A 301 Redirect permanently redirects one URL to another URL, you can use this redirection method if your website is changed or moved to the new one. After the redirection, your old site URL will be moved to the new site URL, so your old domain to send visitors to the new domain. There are different types of redirection among them, 301 redirection is very much useful, it helps the visitors to guide that the content is moved to a new location. Below we will see how to apply the 301 redirect in .htaccess file.

Common uses of 301 Redirects:

Redirecting individual page URL: If you want to redirect the individual page URL into another URL within the same domain, you can apply 301 redirections for this. Enter your domain name in code instead of yourdomain.com

Redirect 301 /old-url https://yourdomain.com/new-url

Redirecting Old domain to new domain: You have changed the domain name but you want to use the same content of your old domain, then you can apply the 301 redirects for the entire domain.  Type your old domain name and new domain name instead of oladomain.com and newdomain.com

RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC] RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]


How to create or edit the .htaccess file?

Step 1: Log in to your domain cPanel account.

cpanel login - 301 redirect in .htaccess

Step 2: Search File Manager in the cPanel, or find the File Manager in the Files section.

301 redirect in .htaccess - File Manager

Step 3: The File Manager opens in a new tab. Inside that click “Settings” which is on the top right side.

301 Redirect in .htaccess - Settings

Step 4: The preference page will open. Check the “Show Hidden Files” checkbox and click “Save“. It will show all the hidden files for you.

301 Redirect in .htaccess - Show hidden files

Step 5: Go to the public_html folder in the File Manager window. There you can see the .htaccess file. If it is a new site and the .htaccess file was not there, you have to create it.

301 redirect in .htaccess - Public_html

Step 6: To create the .htaccess file, Click the +File button at the top right.

301 redirect in .htaccess - create new file

Step 7: The New File window will open. Enter the “New File Name” as .htaccess and click “Create New File“.

301 redirect in .htaccess - new file name

Step8: Now the .htaccess file will show in the public_html folder. To edit this file, select the file and click Edit Option.


Step 9: The editor window will display where you can edit your code based on your requirement as mentioned above.

Step 10: Once you have done the editing, click the “Save Changes” button on the top right side of the page and close the tab.

301 redirect in .htaccess - Save changes


If you are a registered user in SeekaHost and have any queries to be clarified or issues to be sorted, you can raise a ticket through the client area dashboard or email to [email protected]. For immediate interaction or guidelines, contact our support team available in LiveChat at the right bottom corner of the website.