How to run a file without extension as php

rajeevacj

Member
May 27, 2019
9
2
3
India
cPanel Access Level
Root Administrator
Hello,
I generally want to know if this is possible and if possible, how to do this.
I have a file search.php, I want to access it only from the url 'search', so I can't use the .htaccess code like Options +Multiviews. Any help would be appreciated

Thanks.
 

rajeevacj

Member
May 27, 2019
9
2
3
India
cPanel Access Level
Root Administrator
I don't want users to access search.php, I only want them to access the file 'search', whereas multiviews allows access to users to search.php (with the php extension also).
 

rajeevacj

Member
May 27, 2019
9
2
3
India
cPanel Access Level
Root Administrator
I am sorry for late reply, a glass of water spill on my laptop when I was to reply, so I needed some time to get it work.
I fixed the issue myself. The code is the same, but it points to a single file i.e. search.php.

.htaccess

Code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule search search.php [L]
search.php (at the top of the file)
PHP:
<?php
if ($_SERVER["SCRIPT_URL"] == "/search") {
} else {
header("HTTP/1.1 404 Not Found");
exit();
}
?>
I fixed it :)
 
  • Like
Reactions: nixuser