Reputation: 1442
Have file create.php
Want if user types domain.com/create.php
show domain.com/create
in .htaccess above RewriteEngine on
placed this
RewriteRule ^create/?$ create.php [NC]
But if i type domain.com/create.php
, i see .php
how to allow access to create.php
file only from url domain.com/create
?
Upvotes: 2
Views: 848
Reputation: 785146
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
Options -MultiViews
RewriteEngine On
RewriteBase /
# To externally redirect create.php to create
RewriteCond %{THE_REQUEST} \s/+(create)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# To internally forward create to create.php
RewriteRule ^(create)/?$ $1.php [L,NC]
Upvotes: 3