Am wondering how to remove index.php from URLs, every link on my site has index.php in it, for e.g. example.com/index.php/contact-us.

Am using Drupal 8, my server is Apache and php version is 5.6, and am on Shared Hosting.

In the .htaccess file i tried to use

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
That removed the index.php but any new article wont show the images in the homepage(index.php)

then i tried to use

RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
Same thing happened.

What i have now is :-
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

Please advice

Comments

daiwik.addweb’s picture

Please refer this link https://www.drupal.org/node/1183208

danghoaiphuc’s picture

Hi Abzax and All,
May I know if you have the sollution to remove the index.php/ from the url alias without breaking images or paths to existing files on the system? I have followed the referred link but didn'haven't found the sollution to solve. Your help should be highly appreciated and be thankful.

Internet’s picture

Had same issue and this was fixed by running udate.php (removing the index.php from url). I suspect error crept in when site core was updated last.

jnimchuk’s picture

I was getting clean urls through Drupal 8.2. Somewhere in 8.3 I started getting index.php in the URL.

1. This happens only in my production instance. Dev instance, configured exactly the same, works.

2. If I am logged in as an authenticated user, I it also works on Production.

3. Only as an anonymous user in Production do I get the index.php. After "update.php" it will work fine for awhile, then start up again in certain places.

How can I fix this? It is truly a Drupal thing, not Apache.

deiloff’s picture

I have the same problem, but also only on production instance.

Clearing the cache is working for some time.

jnimchuk’s picture

Yes, clearing the cache does help sometimes. Right now I have a job that clears it every hour.

ErnoVanhala’s picture

I am also having this issue sometimes. It seems to be quite random – which is not nice.

C13L0’s picture

I'm also having this issue and sadly, google has started indexing some of the index.php urls which of course are reporting as a 404....help!

Cake, and grief counseling, will be available at the conclusion of the test

jnimchuk’s picture

In my case, when Google finds a URL with index.php it does not index the page.

I've taken a huge hit on SEO. I can't believe that this issue is not being addressed!

David Baggins’s picture

When I am logged in, all Drupal-placed links (like menu, views etc) have index.php in them like example.com/index.php/about instead of example.com/about. If I am logged out, everything is fine. Also, this problem appears when I use an https version of my website. When I use a http version (after deleting redirection from the htaccess file), there is no such problem on my website...

No idea how to fix...

egmont’s picture

Or this example on a Debian 9.4 + Apache2 + ISPConfig, using wildcard to match all sites installed:

No edit .htaccess !

Need only apache2.conf

<Directory "/var/www/html">

 AllowOverride None
</Directory>

to

<Directory "/var/www/html"> Example : http://localhost/drupal85/admin/modules; antes http://localhost/drupal85/index.php/admin/modules

Ср мар 14 19:16:48 MSK 2018
 

 AllowOverride All
</Directory>
jnimchuk’s picture

Changing from None to All works for me.

<Directory "/var/www/html"> 
 AllowOverride All
</Directory>
jnimchuk’s picture

I thought this was working after the "AllowOverride All". But after I upgraded to Drupal 8.5 a few days later, it started coming back again. Randomly. Periodically.

Anyway, I'm tired of this (definite) Drupal issue. I fixed it using a series of Apache redirects.

edruiz_1’s picture

Hello, this issue is driving me nuts... could you share your redirection based solution please.

jnimchuk’s picture

1. First add "Disallow: /index.php/*" in robots.txt file. (This will will help stop Google from indexing pages using index.php in the URL.)

2. Then at the top of the .htaccess file, provide permanent redirects directory by directory for your particular site. For example:

<IfModule mod_rewrite.c>
  RewriteEngine on 

  RewriteRule ^index.php/categories$ /categories [R=301,L]
  RewriteRule ^index.php/categories/(.*) /categories/$1 [R=301,L] 

</IfModule>

For me, it got to the point where Google had stopped indexing much of my site because it was finding all these duplicate URLs (one with index.php, another without).

Now my index.php problem is gone and (slowly) Google is ridding its search index of the index.php URLs.

Good luck.

djkozz’s picture

But wich one is the right code for a web site without directories? Sorry to ask, but I do not want to broke my web site.

gmrossello’s picture

For our project we are having also problems with /index.php/ in the url. 
In our case, problems appear only in the production environtment. The only differences in this environtment are: 
- Two machines are running drupal instances and a Load Balancer is distributing the traffic between them.
- The ssl connection, that os configured in the Load Balancer server.
The machines are working on a centos 7 with a 7.28 version of php.

The AllowOverride All for the correct directory was changed in the httpd configuration file.

In some places, is mentioned that the possible cause of the is in the ssl conf file for the secure site:

https://www.drupal.org/forum/support/installing-drupal/2009-03-10/ssl-an...
https://www.drupal.org/node/475730#comment-1726870

But in our case, the one that has this configuration is the Load Balancer, not the production machines.
Someone found a solution for this issue?

phanosd’s picture

This is not the issue. You copied the files and .htaccess file was not copied because it was hidden. 

Kipling79’s picture

I don't know if this is the problem, or if it is the same problem for everyone, but I noticed index.php was added to all of my URLs this afternoon.

The only thing I changed today was to add Simple XML Sitemap, check the indexing box inside each content type, then index the site. I then submitted that map to google. 

I first noticed the Index.php's after submitting that site map (but they 'could' have been there before). After freaking out and trying my best at htaccess rewrites and google-fu, I chose to uninstall Simple XML Sitemap and my URLs immediately went back to normal. Unfortunately, I lost my sitemap too. 

I will reply again if this "fix" proves to have been coincidence and the index.php reappears.

Edit: I tried to repeat the problem in my identical subdomain, but couldn't. Obviously there are no guarantees that this was or was not a problem with the module, but I am very suspicious about the timing of my original "fix".

Rewted’s picture

I just noticed the index.php issue today and also using the Simple XML Sitemap Drupal module. Did you ever find the cause?

Shane Birley’s picture

I did a quick read of this thread and noted that most solutions were related to the lack of an .htaccess file in the root folder. It might be a good idea to check there first.

---
Shane Birley
Left Right Minds
https://www.leftrightminds.com

Rewted’s picture

Yeah, not the case for me .htaccess is present. Hasn't happened since, but I'll keep an eye on it.

Rewted’s picture

A solution. Install the Redirect Module, the default setting of Enforce clean and canonical URLs will fix the issue. However, there is also a long outstanding bug Route normalizer: Global Redirect in Drupal which apparently is the cause, but hasn't been pushed to Core yet.

djkozz’s picture

But does not work for Google Search Console. So, from time to time I need to request a cache removal for index.php*

hazit’s picture

Hi there. Have raised this issue in case there is some kind of interaction between the sitemap module and this problem:

https://www.drupal.org/project/sitemap/issues/3145126

waelk78’s picture

"Disallow: /index.php/*" in robots.txt file.

foka_patrick’s picture

just add disallow : /index.php/* in your robot.txt file

Amelia_3’s picture

At the point when I am signed in, all Drupal-set connections (like menu, sees and so forth) have index.php in them like example.com/index.php/about rather than example.com/about. In the event that I am logged out, all is well. Additionally, this issue shows up when I utilize a https form of my site astro store. At the point when I utilize a http form (in the wake of erasing redirection from the htaccess record), there is no such issue on my site... 

Pavan Shetty’s picture

I guess your index.php file got corrupted[which was in my case]. the problem solved after i replaced the corrupted index.php file with the new one

Pavan Shetty’s picture

I guess your index.php file got corrupted[which was in my case]. the problem solved after i replaced the corrupted index.php file with the new one