WordPress Permalink Structure

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.

After successful migration of your WordPress site to another server the first thing you probably would wanna to do is to enter the Permalinks settings and check your desired option for permalinks, which in most cases is “Post name” and to save that setting into the database. But since you probably imported database chances are that you are going to see the “index.php” already created itself into the URL structure. If you want to remove index.php from permalink in WordPress here is what you might try to do:

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

If you don’t have direct info from your hosting provider if this module is active on your server you can create info file and check for yourself. Learn how to create PHP info file in this post.

2. Set the permalink structure

Go to 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.

Learn more about Permalinks in WordPress on the official WordPress Codex page.

Additional 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 .htaccess directives. 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.

3 comments

Leave a Reply

  1. nkeene · July 7

    What happens, if that doesn’t work? I’ve followed the steps that you have mentioned here and I still am stuck with /index.php/ being required in my urls.

    • janoshke · July 7

      Hi there,

      Thank you for your comment and you asked a good question as well. I recently had this case and here is what came to my knowlege. There are two things you might want to check server side:
      1. Is mod_rewrite installed and active on your hosting server? (Check with your host company or server admin)
      2. Is mod_security blocking your settings? (Also check with server admin)

      In my case the 2. option apply and here is a little spice that my server admin added to .htaccess file which solved the issue. I will edit the post with this piece of code.

      I hope this helps. Cheers 🙂

  2. Hi, when something works i like to chime in. Simply setting the permalink structure did the trick for me. /%postname%/