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.
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.
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 🙂
Hi, when something works i like to chime in. Simply setting the permalink structure did the trick for me. /%postname%/
Yes. It has worked for a me as well
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?
Hello,
It looks all fine to me… what exactly is the problem you are having?
I needed to update apache2.conf – Thank you for including this in your article. Works good.Lasts long time.
Sure thing. I’m glad you find it useful.
Same here. Thanks George and, of course janoshke.
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
Hi,
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 🙂
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.
I’m happy to hear that it was helpful.
Cheers 🙂
Yes its works ! Thank you , what is the different in the code you given and the real code?
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 🙂
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
Nice 🙂
Thank you for your help it really worked..
Great. I’m glad you find it useful 🙂
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.
Thanks.
Cheers 🙂
Thank you very much for the information, the last steps solved my problem.
Cool. I’m glad it helped! 😉
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?
Not sure if I follow you. Can you please elaborate? You can Email me for details.
Cheers
Wow nice article, i have remove index php in site with the help of your writeup!
Thanks keep it up!
Fixednaijablog.com
Thanks! I’m glad you find it useful 🙂
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!
Nice. You’re welcome. I’m glad it served you well 🙂
Wow. Thank you for your awesome support.
I had been battling this error on my home server for 2 days.
Thank you!
You’re welcome. 🙂
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!
Great! Thanks for the feedback.
Problem solved thanks for this very helpful articles.
You’re welcome. 🙂
Thank you very much!
You’re welcome 🙂
I tried many websites, but no one was working. but the last solution of changing `/etc/apache2/apache2.conf` worked like a charm for me.
Second there is no option for me to add new comment, I can only reply to comment.
Hi, I have tried all the options stated above but unfortunately i am still getting 404 without index.php
Hi shefali,
Thank you for commenting. Can you please describe in more details what exactly is your issue?
thanks for sharing
Thank you sooooo much for your help! It works really well!!!
Thanks buddy (Y).
I have apply the postname in custom link at my website https://infolinkers.com/ and this problem solved. Thanks for saving my time and money
Thank you for the comment. I’m glad it helped.
For IIS, install MS URL Rewrite Module
https://www.iis.net/downloads/microsoft/url-rewrite