Remove extension .php (htaccess)


#1

Hello,

I would like to remove extension .php from my free website.
On OVH my code in the htaccess file works but not here.

This is my htaccess file :
https://pastebin.com/JRtcQZPa

This code works, the php extension is removed BUT the page is a 404 error :frowning:

For example :
contact.php redirects to contact BUT the page displays a 404

Thank you for you help


#2

Can you please post the code you use?


#3

Hello,

Thank you for your answer !
Here is my code :

RewriteEngine on
 
# Pour supprimer le slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/$
RewriteRule ^ /%1 [R=301,L]
 
# Suppression de l'extension php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ (.*)\.php [NC]
RewriteRule ^ %1 [R=301,L]
 
## Redirection du index vers /
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_URI} /index.(htm|html|php)$
RewriteCond %{THE_REQUEST} /index.(htm|html|php)
RewriteRule ^(.*)index.(htm|html|php)$ /$1 [R=301,L]
RAW Paste Data

#4

Your website please.


#5


please


#6

https://proschool.000webhostapp.com/contact doesn’t exist that is why…?


#8

Hello

Contact.php exists. With URL rewriting it’s possible to remove the php extension and call contact (whitout .php)

PS : this code works on OVH

Thank you


#9

AH I see now I’ll shut up and let someone else advise then :stuck_out_tongue:

@teodor maybe


#10

Thank you Infinity ! :smile:


#11

Try adding this to your htaccess

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

#12

It works ! Thank you very much


#13