Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting 404 error when removing file extension worked on wamp but not working on lamp

Tags:

php

.htaccess

in htacesss file in admin folder, removed php extension on wamp although worked fine. when moved to ubuntu with lamp server. it's giving 404 not found. but htaccess working perfectly for other thing like index routing.Below what i am using on htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
DirectoryIndex index.php
like image 460
Muthukrishna C Avatar asked Dec 09 '25 00:12

Muthukrishna C


1 Answers

Try this rule:-

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

OR

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

OR

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

If this global rules is not working for you then try below code also:-

In this code replace 'work' with your project root directory.

RewriteEngine on
RewriteBase /work/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule .* $0.php [L]

In linux you need to ON rewrite module.

open your terminal(ctrl+alt+t) and run this command.

sudo a2enmod rewrite

then restart apache2 by this command:-

sudo service apache2 restart

This tutorial link will help you.

Hope it will work for you :)

like image 107
Ravi Avatar answered Dec 10 '25 13:12

Ravi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!