How to remove ‘index.php’ from permalink in WordPress

After WordPress migration to another server, which don’t necessarily have to have the same settings as the one you are migrating from, there is a chance of having “index.php” added to your URL. This can often lead to 404 missing page error and it disrupts friendly URL’s. Learn how to remove index.php from permalink in WordPress.

1. Find out if “mod_rewrite” is enabled on your server

If you don’t have direct info from your hosting provider that this module is enabled on your server or not, you can use phpinfo() and check for yourself.

2. Set the permalink structure

Go to Admin Dashboard > Settings > Permalinks and choose “Custom Structure” option and enter in the field: /%postname%/ and click on Save Changes button.

3. Edit your .htaccess file

Copy the following directive into your .htaccess file which is located in the root of your website folder:

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

This should be enough to remove the index.php from the URL structure.

Other known issues

Sometimes the steps described above don’t give any results in removing the index.php from your permalink structure, and here is what may cause the trouble. On some servers with tight security the mod_security is blocking your settings thus index.php still remains in the URL structure. Try adding this piece of code in your .htaccess file above the rules described in step 3 of this post :

<IfModule mod_security.c>
SecFilterEngine Off
</IfModule>

One more thing to check is config file for Apache which can also override your .htaccessdirectives. Look for Ubuntu default /etc/apache2/apache2.conf file and change the entry for / and /var/www from AllowOverride None to AllowOverride All. Then restart Apache server and hopefully it can solve the issue as well.

Please follow and like us:
error
Avatar

Author:

Sr. Software Engineer at Articleye

Leave a Reply

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