Why is index php in my wordpress url?

I have a problem with index.php in my WordPress website. This problem is arriving since I have changed and migrated my WordPress database from WordPress to mydatabase. I have also changed my table prefix name.

Now problem is that, I am unable to see my pages and posts without index.php.

http://example.com/index.php/postname/

I have tried the following solutions:

  1. Change permalinks setting (nothing changed).

  2. Change rewrite module with .htaccess file (nothing changed).

  3. Enable rewrite module in my apache2 server (nothing happened).

  4. Deleted value of rewrite_module of wp_options table for cache purpose (nothing happened).

  5. If i set permalink for %postname%

e. g. http://example.com/postname/

Then i get 404 error.

My .htaccess code is:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


# END WordPress

Please anybody provide me correct solution. How to get rid of index.php?

Why is index php in my wordpress url?

Armali

16.9k13 gold badges54 silver badges157 bronze badges

asked Sep 17, 2015 at 11:20

Why is index php in my wordpress url?

9

Go to your WP-ADMIN-->Settings-->Permalink and use the permalink structure change there, if it generate any .htaccess file copy the content and update your .htaccess file.

Or Check if your hosting mod_rewrite is enable by creating a file phpinfo.php with content,


Upload this file and browse via Browser. So you know which modules are enabled. You need mod_rewrite enable to remove index.php from URL.

More details Check this link

answered Sep 17, 2015 at 11:57

1

  • Hello,

    I have WordPress 5.4.1 installed on my server.
    The URL of the page is http://192.168.61.7/wordpress/index.php/page-name
    I changed the permalink structure to http://192.168.61.7/wordpress/page-name and updated the .htaccess folder with the following code:

    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]

    and im still not able to get rid of the index.php in the URL

    • This topic was modified 2 years, 3 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic

  • Why is index php in my wordpress url?

    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 you can check the below methods.

    Why to Remove index.php From Permalink?

    Index.php is not considered a user-friendly URL and it may lead you to a 404 error. Besides, there is no benefit to keeping index.php in the URL, except trouble. If you are a blogger and write articles, then you might target long-tail keywords. Keeping index.php in the URL makes it too long. 

    Therefore it is wise to remove index.php from the permalink.

    Here, we are going to show you two different methods. First, try method one, most of the time this method solves the problem. If it doesn’t work try method two. Let’s see.

    The most common reason for index.php appearing is improper permalink structure. Therefore first check if the structure is set properly. 

    To check it, navigate to Settings -> Permalinks

    Now check if the permalink structure is set to ‘Post name’. If not then change it to post name and check if the index.php is removed. If not, then you have to try the second method. 


    Method 2: Adding code to .htaccess file to remove index.php

    If method one doesn’t work this surely will. Everything is described step by step, make sure you don’t miss anything.

    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 the server, open your website root directory. Now create a PHP file named mod_rewrite.php

    Why is index php in my wordpress url?

    Add the following code to this file.

    Why is index php in my wordpress url?

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

    Why is index php in my wordpress url?

    Now add the following code to the .htaccess file.

    RewriteEngine On
    RewriteRule ^.*$ mod_rewrite.php
    Why is index php in my wordpress url?

    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 disabled’, make sure to delete the .htaccess file that you created earlier and rename the original file to ‘.htaccess’.

    Why is index php in my wordpress url?

    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. 

    Why is index php in my wordpress url?

    Step 3: Edit .htaccess file

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

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

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    # END WordPress
    

    This will be enough to remove index.php from the 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. 

    
    SecFilterEngine Off
    
    

    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. 

    You may also want to know How to edit and change post/page URL in WordPress. It’s a post that describes the ways to change or edit post/page URL easily.

    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. 

    Why does my URL say index php?

    The most common reason for index. php appearing is improper permalink structure. Therefore first check if the structure is set properly. To check it, navigate to Settings -> Permalinks.

    What does index php do in WordPress?

    index. php – The index file basically loads and initializes all your WordPress files when a page is requested by a user.

    How do I remove index HTML from WordPress URL?

    How to Remove ..
    Open htaccess file. Open terminal and run the following command to open . htaccess file. ... .
    Remove . html extension from URL. ... .
    Restart Apache web server. Restart Apache server with following command $ sudo systemctl restart httpd..

    How can I remove Index php in the URL generated laravel?

    One way to get rid of it, is to check the route in Laravel and issue a redirect there if needed. Here's one way to do this in app/Providers/RouteServiceProvider. php . This will redirect any URL with index.