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]
# 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

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.


Leave a Reply

  1. nkeene · July 7, 2017

    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, 2017

      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. cultureexperienceblog · July 7, 2017

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

  3. lanse · July 7, 2017

    what happened with my website https://top10listguide.com/, when i remove the index.php, i can’t open the post page, they were 404, why?

    • janoshke · July 7, 2017

      It looks all fine to me… what exactly is the problem you are having?

  4. George · July 7, 2017

    I needed to update apache2.conf – Thank you for including this in your article. Works good.Lasts long time.

    • janoshke · July 7, 2017

      Sure thing. I’m glad you find it useful.

  5. Viktor Boritas · July 7, 2017

    Heyy Dejan,

    Thank you for the great help above! Is this procedure works on nginx servers as well? Anything different that worth to know? Best, W

    • janoshke · July 7, 2017

      Thanks for the comment. I tested it with Apache so far, but if you find out it works on nginx please do share in the comments.

      Cheers πŸ™‚

  6. OriginHF · July 7, 2017

    Thank you so much. I don’t have much web experience and your article saved me so much time fixing the permalinks on my site.

    • janoshke · July 7, 2017

      I’m happy to hear that it was helpful.

      Cheers πŸ™‚

  7. Vishnu Ozhukoor · July 7, 2017

    Yes its works ! Thank you , what is the different in the code you given and the real code?

    • janoshke · July 7, 2017

      There is no code changing involved. You just give the command via htaccess file to overwrite the piece of the URL, and that’s it πŸ™‚

  8. Kshitiz Saxena · July 7, 2017

    Worked like a charm!
    There was a file called htaccess in the web root. After several failure attempts, I saw that file name, renamed it to .htaccess and it all worked – WordPress site was hosted on Fedora Linux

  9. ismail · July 7, 2017

    Thank you for your help it really worked..

    • janoshke · July 7, 2017

      Great. I’m glad you find it useful πŸ™‚

  10. Vaggelis Tsagklis · July 7, 2017

    That is so helpful article. The most important is the Server side, where the mod_rewirte has to be enabled. The rest is just account settings.


  11. Mosiah Orellana Troncoso · July 7

    Thank you very much for the information, the last steps solved my problem.

    • janoshke · July 7

      Cool. I’m glad it helped! πŸ˜‰

      • feryox777 · July 7

        Hi!!! the last step it works for me too, but, exist a form to do that with code? is that results from a bad installation or configuration?

        • janoshke · July 7

          Not sure if I follow you. Can you please elaborate? You can Email me for details.


  12. Mass Killer · July 7

    Wow nice article, i have remove index php in site with the help of your writeup!

    Thanks keep it up!


    • janoshke · July 7

      Thanks! I’m glad you find it useful πŸ™‚

  13. KMyers · July 7

    Thank you so much! I had to pull up an additional video to assist with my C:panel and the Mod_rewrite as I am a total newbie when it comes to this, but this helped me so much, and fixed my website. Truly appreciate it!

    • janoshke · July 7

      Nice. You’re welcome. I’m glad it served you well πŸ™‚

  14. MOLGUER · July 7

    Wow. Thank you for your awesome support.
    I had been battling this error on my home server for 2 days.
    Thank you!

  15. jhenry · July 7

    Hi janoshke,
    Thanks for the excellent tips! I have been tolerating the ‘index.php’ in my URLs for a while now then decided to Google a way to remove them. I didn’t think it could be done as the ‘index.php’ was probably serving the ‘.html’ page. It’s not so! The whole thing was unnecessary.
    I don’t know if it makes a difference but here is my setup:
    – I’m hosted at Hostinger,
    – web server is listed some places as ‘LiteSpeed’ (for caching, I believe), other places as Cloudflare, but I think it’s actually apache
    – WordPress version is 5.4.2

    I only had to use the simplest method you described to be rid of the ‘index.php’ from my URLs, namely, go to WordPress Dashboard > Settings > Permalinks > Set to ‘Custom’ and enter /%postname%/
    Save Changes and works like a charm! URLs are now like http://www.example.com/privacy-policy
    Thanks again!

  16. Marjun · July 7

    Problem solved thanks for this very helpful articles.