Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove file extension htaccess not working

the following code is not working to remove the file extension .php

Options +FollowSymLinks
RewriteEngine On

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

my url not changing from example/about.php to example.com/about

like image 263
Mukilan R Avatar asked Oct 20 '25 12:10

Mukilan R


2 Answers

I have found the answer. Its working. the code is as follows to rewrite and redirect the url

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

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]

It rewrites and redirects the URL. Thanks all for ur answers.

like image 65
Mukilan R Avatar answered Oct 23 '25 00:10

Mukilan R


This RewriteRule should remove the .php extension from a request. Try placing it before your RewriteConds.

RewriteRule ^(.+)\.php$ /$1 [R]
like image 21
Koen Avatar answered Oct 23 '25 02:10

Koen



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!