.htaccess files, also known as distributed configuration files, are use to manage configurations for websites that are running on Apache webserver.
Complete List of Apache .htaccess Rewrite Rules for WordPress
If your WordPress installation is running on Apache, then you will need to learn how to change the web server configuration for WordPress. In this tutorial, we will show you how to do the following redirect with WordPress.
- Default .htaccess Rewrite Rules for WordPress
- 301 Permanent Redirect
- 302 Temporary Redirect
- Force Non-www URL to www
- Redirect www URLs to Non-www
- Force HTTP to HTTPS
Default .htaccess Rewrite Rules for WordPress
WordPress installation usually comes with a default .htaccess in the root directory. But if your do not have one, you can copy the following into a text editor and save the file as .htaccess
, and then upload the file to the root root directory of your WordPress installation.
htaccess Rule for WordPress URL 301 Permanent Redirect
301 is a HTTP Status Code, it tells the search engine that a URL is permanently moved to another URL. See below code snippet on how to do a 301 permanent redirect with a WordPress URL:
Rewrite Rule for WordPress URL 302 Temporary Redirect
Similar to 301, 302 is also a HTTP Status Code that tells search engine that a URL is moved to another URL, but the redirection is temporary. See below code snippet on how to do a 302 temporary redirect with a WordPress URL:
Force WordPress Non-www URL to www
The following .htaccess rewrite rule will redirect all non-www URLs to www.
Force www WordPress URLs to Non-www
Using the following WordPress .htaccess rewrite rule will redirect all www URLs to non-www.
Force WordPress To Use HTTPS
Below .htaccess code snippet will force all visitors of your site to be on HTTPS.