Is it possible to use .htaccess to prevent a page from being served unless it is by a rewrite rule? for example I have clean URLS so a call to xyz.com/hi
serves xyz.com/hi.php
.
I would like to achieve if the called url = xyz.com/hi.php
that the page opps.html
gets served, but the normal xyz.com/hi
still works.
thx Art
DirectoryIndex h1.php
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# stop calling page by ext
RewriteRule .*\.(php)$ opps.html [L]
# main start page
RewriteRule ^hi$ hi.php [L]
You need to add a condition to prevent php extensions from getting rewritten to oops.html
. If you want to prevent actual requests for php pages, you can use the %{THE_REQUEST}
variable inside a RewriteCond
:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.php\
RewriteRule .*\.(php)$ opps.html [L]
This way, internally re-written URI's that end with .php
won't get rewritten to oops.html
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.