How to hide file extension with .htaccess + Access Restriction

Guys, how to remove file extension using .htaccess. example: the filename was "/home.php"

of course after using .htaccess

now he can access using the link "/ home"

it is possible to redirect usage to 404 error if they visit "/home.php" instead of "/ home"

Thank!

+3


source to share


3 answers


You can simply use Multiviews

:

Options +Multiviews
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php
RewriteRule ^ /%1 [L,R=301]

      



This redirects /home.php

to /home

, but you can replace the 301

brackets with 404

if you insist on returning "not found".

+2


source


You can use this rewrite rule .htaccess

to remove the extensionphp

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

      



Hello,

Source: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

+1


source


This snippet will rewrite *.php

in*

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

      

0


source







All Articles