Akshay Shrivastav
Akshay Shrivastav

Reputation: 19

.htaccess - How to Override Url Even If someone Puts the .PHP after the filename

I have created the .htaccess file to rewrite url for .php

Before creating the .htaccess files

Url was like : www.xyz.com/contact.php

After creating the file

Its like : www.xyz.com/contact

But if someone writes in the url

www.xyz.com/contact.php

The .PHP extension is displayed hoe to hide it even if someone enters it manually

Upvotes: 0

Views: 160

Answers (1)

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

the following code will remove .php even if users write it :

RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

Upvotes: 1

Related Questions