1

I have a URL like http://example.com/index.php/fruit/1a2b3c

I want to get the URI's for which I have written a code.

Now I want to remove the index.php from the visible URL, it should work even when the URL is http://example.com/fruit/1a2b3c and it should still point to index.php

I am on apache2 using PHP 7

zegulas
  • 417
  • 2
  • 6
  • 18
  • Possible duplicate of [Remove index.php from url by htaccess](https://stackoverflow.com/questions/20673235/remove-index-php-from-url-by-htaccess) – Ali Sep 12 '17 at 08:45
  • Possible duplicate of [htaccess remove index.php from url](https://stackoverflow.com/questions/4365129/htaccess-remove-index-php-from-url) – AIT MANSOUR Mohamed Sep 12 '17 at 08:51
  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Masivuye Cokile Sep 12 '17 at 08:59
  • You have to rewrite the rules in .htaccess file. It might solve your issue. – dhruv Aug 03 '19 at 10:20

2 Answers2

1

Add following code to your .htaccess file.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
  • Hey thanks a lot for your answer, it did solve my issue, could you also please explain how it works, line by line? I am finding it difficult to understand what and how it does that? – zegulas Sep 13 '17 at 05:11
0

change your .htaccess file to,

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

hope this will work.

Jithin Varghese
  • 2,018
  • 3
  • 29
  • 56