How To Remove index.php From Permalink In WordPress

remove index.php

After a successful migration of your WordPress site to another server, the first thing you would like to do is enter Permalinks settings and remove index.php from permalink in WordPress. Having index.php in permalink often can lead to 404 missing page error and it disrupts User-Friendly URLs. 

Since you probably imported the database, there’s a good chance that you are going to see ‘index.php’ already create itself into your URL structure. If you want to remove index.php from the permalink here’s what you can do:

Removing index.php From WordPress Permalink

Follow these 3 simple steps –

Step 1: Make Sure ‘mod_rewrite’ is enabled on your server

At first, you log in to your hosting site and make sure your ‘mod_rewrite’ is enabled. If this module is active on your server, you will be able to create an info file and check for yourself. 

In cPanel, Mod_Rewrite is compiled with Apache by default. E.g.

 root@server [~]# httpd -l|grep rewrite
  mod_rewrite.c

If you want to check whether mod_rewrite is enabled on server, open your website root directory. Now create a php file named mod_rewrite.php

Add following code in this file.

<?php echo "Mod_rewrite is activated!"; ?>

Afterward create a .htaccess file and rename the original .htaccess file to .htaccess_1 if you have it.

Now add following code to the .htaccess file.

RewriteEngine On
RewriteRule ^.*$ mod_rewrite.php

Enter your website. If you see a message such as ‘Mod_rewrite is activated’, then it is enabled on your server. If you find anything else such as “mod_rewrite is disable’, make sure to delete the .htaccess file that you created earlier and rename original file to ‘.htaccess’.

Step 2: Set the Permalink Structure

Now navigate to Dashboard -> Settings -> Permalinks, then choose the ‘Custom Structure’ option and enter /%postname%. Then click on save changes. 

Step 3: Edit .htaccess file:

Now open ‘File Manager’ from your hosting site and open the .htaccess file that is located in the root of your website folder(I am using cPanel). 

Now copy the following code and paste it on your .htaccess file. 

# 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 will be enough to remove index.php from permalink in the WordPress site. 

Additional Known Issues That Might Occur

Sometimes steps described above won’t give you any results. On some servers with high security, it may appear that ‘the mod_security is blocking your settings’ thus the index.php remains on your URL structure. To solve this try adding the below piece of code in your .htaccess file. 

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

Last Words

One more thing, check for a config file for Apache which may 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. Afterward, restart the apache server and hopefully, it will solve this issue as well. 

Let me know after removing index.php from your permalink. If you face any other issues ask me I will be happy to help and don’t forget to share this post. 

close

Easy WP Tweaks

10X Your Site Growth!

Join the growing library of Easy WP Tweaks to grow your WordPress site.

Leave a Comment

Copy link
Powered by Social Snap