0

I want to remove the index.php from URL in CodeIgniter while using Laragon

I have edited the .htaccess file in CodeIgniter and applied a rule; I also changed the index_page variable to empty string in application/config/config.php.

It, as expected, works completely fine in a web environment setup using WampServer/xampserver but fails when using Laragon.

The problem may be with the Laragon environment but I don’t know how to fix it.

How can I make it work in a Laragon environment? (As Working in Wampserver).

My .htaccess file contains the following code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myFolder/index.php/$1 [L]
Tufail Ahmad
  • 396
  • 3
  • 15

2 Answers2

1

I solved the problem then by getting some help on Laragon community

The fix is actually simple.

Laragon is compiled with its httpd.conf set to reject overwrite on the document root.

To edit this, check the file on

{LARAGON_ROOT}/bin/apache/httpd{other-version-details}/conf/httpd.conf

and the file somewhere around line 251 to 278 change AllowOverride to All and restart your Laragon Server.

That fixes it

NOTE:

You have to do settings in your codeIgniter, like your index_page variable should be empty in

application/config/config.php

$config['index_page'] = "";

And the .htaccess file contains the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourFolderName/index.php/$1 [L]

If still it doesn't work, find all AllowOverride None in httpd.conf and change them to AllowOverride All. Restart your computer if necessary.

Tufail Ahmad
  • 396
  • 3
  • 15
0

In C:\laragon\etc\apache2\sites-enabled you are going to find all the v-hosts of laragon you have in your working directory.

When you find the codeigniter one and you open to edit it you are going to see a normal apache VirtualHost.

Change this line: <Directory "C:/workspace/my_project">

to : <Directory "C:/workspace/my_project/index.html">

Rename the laragon .conf file and remove auto. from the file name.

Restart everything.

careful to open the right v-host. Laragon creates 2 v-hosts, 1 with your extension defined in settings and one with .com extension.

Edit:

<VirtualHost *:80> 
    DocumentRoot "C:/laragon/www/gmap_polygons/application/""
    ServerName gmap_polygons.dev 
    ServerAlias *.gmap_polygons.dev 
    <Directory "C:/workspace/woo-backend-laravel/application/">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# If you want to use SSL, enable it by going to Menu > Apache > SSL > Enabled
pr1nc3
  • 8,108
  • 3
  • 23
  • 36
  • I found .conf file of my project in that folder sites-enabled, I opened it, rename directory name as you mention, restart everything, but it didn't work – Tufail Ahmad May 14 '19 at 08:55
  • Can you modify the DocumentRoot like above to include the index.html, as well and restart? Also are you sure it's the index.html and not the index.php you want to bypass? – pr1nc3 May 14 '19 at 08:56
  • let me check it – Tufail Ahmad May 14 '19 at 09:00
  • I also modify the DocumentRoot. When i run it without including index.php it still shows me 404 not found, and it remove index.html from .conf file automatically – Tufail Ahmad May 14 '19 at 09:03
  • My bad, after you do the changes please remove the `auto` from the conf file name – pr1nc3 May 14 '19 at 09:07
  • I renamed this auto.gmap_polygons.dev.conf to this gmap_polygons.dev.conf, doesn't work, – Tufail Ahmad May 14 '19 at 09:14
  • change the .dev extension to .test. New browsers have stopped support .dev and creates problems (chrome for example) – pr1nc3 May 14 '19 at 09:15
  • this is the code inside .conf file DocumentRoot "C:/laragon/www/gmap_polygons/index.html" ServerName gmap_polygons.dev ServerAlias *.gmap_polygons.dev AllowOverride All Require all granted # If you want to use SSL, enable it by going to Menu > Apache > SSL > Enabled – Tufail Ahmad May 14 '19 at 09:15
  • it still doesn't works, i renamed to this gmap_polygons.test.conf, I have checked it in Microsoft Edge. also doesn't work there – Tufail Ahmad May 14 '19 at 09:18
  • Edited my answer can you try now? Don't forget to restart – pr1nc3 May 14 '19 at 09:19
  • I applied the edited, it now give me error, service apache cannot start: Reasons, then there are a lot of reasons – Tufail Ahmad May 14 '19 at 09:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/193314/discussion-between-tufail-ahmad-and-pr1nc3). – Tufail Ahmad May 14 '19 at 09:29