2

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.

Please advice

2 Answers 2

3

This is what I added to my apache config.

# Sometimes (multiple instances of) index.php/ get(s) inserted in URLs
# Remove them
RewriteCond %{REQUEST_URI} ^/(index.php/)+(.*)
RewriteRule ^.*$ /%2 [R=301,END]

Apparently, some "simple XML sitemap" version introduced these index.php parts and submitted them to search engines and now I get hits with those unclean urls.

Configuring drupal to not use them is the one thing, but telling clients those URLs are not valid anymore is another thing. That's where the above comes in handy. It simply removes all index.php/ parts in a URL.

NB: This has to be placed BEFORE all other rewrite rules!

Sign up to request clarification or add additional context in comments.

1 Comment

This finally worked for me. Stumbled upon it while taking a look at the generated sitemap.xml from simple sitemap. Now it's working again!
0

Please take a look at the following Drupal 8 documentation: https://www.drupal.org/docs/8/configuring-clean-urls/enable-clean-urls

This should help you to enable clean URLs.

Additionally: You might want to check the following issue and comments for your problem: Enable Clean URLs

Extension: Try checking the src URL on your images (If they contain the index.php, if not it might be a permission misconfiguration)

Edit: Try this code in your .htaccess

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

On a side note: You might want to consider switching to PHP7 since active support for PHP5.6 will end soon. (Source)

4 Comments

I tried almost everything there, still facing the same problem.
I tried them as well, still same problem and now when i use this RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L] it actually adds index.php !!! the funny thing is the same website on my localhost is working perfectly without any index.php in every url (am using the same .htaccess file)
Updated my answer again :P
That is the same code i have now, i swear to god am going nuts here, i dont know what i did exactly, but with this code that u posted now, which is my default, everything is working now. but when i access my /user page it will redirect me to index.php then i need to access site.com/index.php/user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.