How to Remove index.php from URL WordPress [ Fixed ]

If you are using a WordPress website, you may notice that the URL of your website contains index.php at the end and this may be due to some reasons such as, you have just migrated your site to another host or maybe the permalinks settings are not correctly done.

So if you are facing this issue and want to know how to hide index.php from URL, well you have landed on the right page, as I will be sharing a few quick methods that will help you in resolving your issue within no time.

Also read: How to Remove Category from WordPress URL

Why to remove index.php from URL?

Index.php at the end of the URL may contribute to a 404-page missing error and also it is not considered to be a user-friendly URL. If you are a blogger and writing articles, you might sometimes target long-tail keywords so if your URL has index.php at the end then the overall URL may become too long while using these long-tail keywords.

So if there are no benefits of having index.php in the URL and you are getting in trouble sometimes due to its presence so it is better to remove it. With that being said let’s head over to our main topic of hiding index.php from URL.

Also Read: How to Check the Version of WordPress

3 Simple Methods to remove index.php from URL WordPress

In this guide, I will be showing three methods to remove index.php from URL in WordPress. The first method is setting permalink structure manually while in the second method, I will be using code in order to remove index.php from the URL

The first reason why index.php appears in the URL might be because the structure of permalinks is not set properly in WordPress Settings. So to verify if the structure of permalinks is set properly, let’s check the permalink tab in WordPress Dashboard.

In your WordPress Dashboard, go to Setting > Permalinks, and there you will see common settings for URL. Now if the permalink structure is set to custom structure or any other, then change it to post name. Once the structure is changed to the post name save the changes and check if the index.php is removed.

Changing Permalink structure in WordPress Settings

I hope if the permalink structure was not set to post name before and now when you changed it, the index.php should disappear but if it is still not changed or the structure was already set to post name and this method hasn’t worked for you then check my second method.

2) Adding Modified Code to htaccess file to remove index.php

If the first method has not worked for you then try this method. To utilize this method go to the htaccess file of your WordPress website from Cpanel. To do so, log in to your hosting account > Open Cpanel > Open File Manager > in File manager look for Public_html.

Now in the public_html folder, if htaccess file is visible then open it, but if you couldn’t find it then on your screen you can see the settings menu, click on it and mark the Show hidden files option checked, click on save, and now you will see htaccess file.

cPanel file manager
Public_html in file manager
htaccess file in filemanager

Now add this below code in the htaccess file by clicking on the edit button at the top of your screen.

# 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

Once you paste the above code in htaccess file, save the changes and now index.php will be completely gone from your website URL. But if your website has tight security then the above code will not work unless you insert the below code too in htaccess file:

<IfModule mod_security.c>
SecFilterEngine Off

Make sure to always backup your website before working with coding, since any small mistake in code can lead to website crash. However, if you don’t know how to take backup, I have written a guide on how to take backup of WordPress site for free

3) Editing Your Theme’s Functions.php File to remove index.php

This method of removing index.php from WordPress URL is more simpler than the second one because you can add code directly in WordPress without needing to access hosting files. All you have to do is to add the below code in function.php file of WordPress:

function remove_index_php($string) {
    if ($string == "index.php") return "";
    return $string;

add_filter('rewrite_rules_array', 'remove_index_php');
add_filter('request', 'remove_index_php');
add_filter('init', 'remove_index_php');

If you don’t know how to add code in function.php file, no worries, you can visit my guide on how to edit function.php file in WordPress which will give you detail instruction to add custom code.

FAQ ( How to Remove index.php from URL WordPress )

Why is there Index.php in my WordPress URL?

There is not always index.php at the end of URL in WordPress websites but sometimes while a site has been migrated to another hosting or maybe the permalinks settings are not done properly in WordPress Settings then this may lead to the presence of index.php at the end of the URL.

How to remove index.php from WordPress URL?

To remove index.php from your WordPress URL, login to your WordPress Dashboard, go the Settings > click on permalinks, and there change the permalink structure to Post name. Now check your website URL, the index.php will be gone.

How to remove index.php from URL through htaccess file?

If you have changed your permalink structure to post name but still index.php is visible on URL then add the below code in the htaccess file which is located in the root directory of your WordPress files.

# 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

Final thoughts ( Conclusion )

If you were worried about why your website URL is showing index.php at the end and were looking for an easy fix, then I hope this guide would have surely helped you in hiding or removing index.php.

The first method is easy to use but the second method needs coding knowledge and you have to be careful while editing these sensitive files, but if you followed our method step by step then you can easily remove it from the URL.

If you still having issues in removing the index.php from your URL then you can contact me through Contact Us form, describing your issue and I will surely help you out with it. Thank you for reading our comprehensive guide.

Please leave a comment below if our methods worked for you or also if you have some queries to ask, I will reply to you as soon as possible. Have a good day ahead…!

You May Like to Read:

How to Find WordPress Admin Login URL

How to Make WordPress Site Private

How to Change WordPress Login URL

How to Link External PHP File to HTML ( 2 Easy Methods )

How to get Current Page URL WordPress ( 2 Easy Ways)

Hamza Afridi is a Full stack Web & WordPress developer and writer with 5+ years of experience. He is Founder of, a blog on web development, SEO, and digital marketing tutorials. He enjoys learning and sharing new technologies.

2 thoughts on “How to Remove index.php from URL WordPress [ Fixed ]”

Leave a Comment