Creating WordPress 301 Redirects in .htaccess File

It is recommended that you create 301 redirects for any URLs in your website that may change either due to page renaming and organizing activities or because of a site rebuild. The guide below will assist you in creating these redirects in your website’s .htaccess file.

You will find the .htaccess file in your website’s httpdocs folder. It is a hidden file which can be accessed and edited in your Plesk file manager.

When you open this file, you will find the built-in WordPress rewrites that will look something like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /redirects/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /redirects/index.php [L]
</IfModule>
# END WordPres

We recommend that you place your own redirects before WordPress begins it’s rewrites.

Errors in your .htaccess file can cause site disruptions. We recommend testing all modifications in a local or development environment prior to production. If any of this is making you queasy, we understand. Check out our hostmaster or webmaster support services and reach out to Valice to assist you with creating and implementing these 301 redirects.

Surround your redirects in the code below:

# BEGIN Custom Rewrite Rules
<IfModule mod_rewrite.c>
RewriteEngine On


</IfModule>
# END Migration Rewrite Rules

The redirects go after “RewriteEngine On” and before “</IfModule>

Example Redirects

Regular Expression Key:
^ – This indicates the beginning of the URL
$ – This indicates the end of the URL
– The backslash will escape the following character to be interpreted literally as it may conflict with a regular expression character (/) – This represents a forward slash in the URL (backslash used as indicated above)
(.*) – This represents nothing or anything so anything after will also be included in the redirect
(/?) – This means that there may or may not be a forward slash in the URL and so both options are included in the redirect

The example below will redirect https://example.com/contact-us/ and https://example.com/contact-us to https://example.com/contact/

RewriteRule ^contact-us(/?)$ /contact/ [NC,R=301,L]

The example below is more expensive but it will redirect https://example.com and https://example.com/contact-us/anythingafter (usefully only for lots of sub-pages) to https://example.com/contact/

RewriteRule ^contact-us(/?)(.*)$ /contact/ [NC,R=301,L]

The example below shows a leaner and more specific way to redirect specific sub pages of the old URL to the new single URL

RewriteRule ^contact-us/(open-a-service-request|account-management|critical-support|service-requests)(/?)$ /contact/ [NC,R=301,L]

The example below will redirect specific sub pages to more specific URLs

RewriteRule ^contact-us/open-a-service-request(/?)$ /contact/open-a-service-request/ [NC,R=301,L]
RewriteRule ^contact-us/account-management(/?)$ /contact/my-account/ [NC,R=301,L]
RewriteRule ^contact-us/critical-support(/?)$ /contact/critical-support [NC,R=301,L]

The example below will redirect a URL that has an ending of .aspx to a new WordPress URL

RewriteRule ^contact-us(/.aspx)$ /contact/ [NC,R=301,L]

If you prefer remote hands from a friendly Valice support professional to assist you, we have membership plans for that. Or if you just want one-time help, click here to schedule a session.