How To Set Up Mod Rewrite for WordPress Permalinks
Most of the pages in your WordPress website—including but not limited to—About Us page, Contact Us page, and blog posts don’t have their own website files. We tend to look for an about us file whenever https://yourdomain.com/aboutus link shows an error on a browser but can’t find any. This is because the permanent links (permalinks) are manipulated using a mod_rewrite module in the web hosting program. The rules and conditions are written via codes in .htaccess file. This article covers:
- How To Generate .htaccess File via WordPress Dashboard
- How To Manually Setup Mod Rewrite for WordPress Permalinks
How To Generate .htaccess File via WordPress Dashboard
WordPress automatically writes these codes and creates the .htaccess file for you. Follow the steps below on how to do it in your WordPress dashboard.
- Log in to your WordPress dashboard via the link yourdomain.com/wp-admin (replace yourdomain.com with the domain of your website) or on any of the methods below depending on your web hosting plan.
- Click Settings on the menu bar at the left side of the page.
- Click Permalinks.
- Click the radio button that corresponds to your preferred permalinks format. Skip this step if changes are not necessary.
- Click the Save Changes button.
The .htaccess file is stored in your website’s directory that you can access via cPanel’s File Manager or via connecting to FTP.
How To Manually Setup Mod Rewrite for WordPress Permalinks
The .htaccess file can be manually created or edited if WordPress doesn’t automatically do it for you. Follow the steps below on how to set it up manually.
- In your website directory, look for a .htaccess file. If none is existing, create a website file with that file name.
TIP:- The main domain’s website files are in public_html folder
- An addon domain’s website files are in the addon directory.
- A subdomain’s website files are in the subdomain’s directory.
- Copy the code based on the setup of your WordPress website on the hosting.
Basic WP (default) – Single website with no redirections.
# BEGIN WordPress RewriteEngine On RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
Multisite for WordPress 3.5 and up
Subfolder – Copy the codes in the box below if your website is in a subfolder with a URL format of http://yourdomain.com/store in which yourdomain.com is your website’s domain name and store is the subfolder name.
RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L]
Subdomain – Copy the codes in the box below if your website’s URL is a subdomain. An example of a subdomain is http://store.yourdomain.com.
RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*\.php)$ $1 [L] RewriteRule . index.php [L]
- Edit the .htaccess file via cPanel’s File Manager or FTP.
- Click the Save Changes button on the text editor.
Do not hesitate to contact our Singapore or Australia Support Team if you have further questions.