开发者

How to allow only one file in Apache

开发者 https://www.devze.com 2023-04-13 04:06 出处:网络
I have a bootstrap file which is index.php and I only allow this page to be called by people not other ones.

I have a bootstrap file which is index.php and I only allow this page to be called by people not other ones.

I've come up with the code below and I received an Internal 500 error. I like to show the log files but I cannot since I am running this on the开发者_JAVA百科 shared hosting but what I know is it is CGI mode.

I put that code in .htaccessand received error and put it in php.ini and didn't work.

<File /index.php>
  Allow from all
  Require None
  Satisfy Any
</File>

What's I am doing wrong?


What I do is just redirect all requests to the index.php file and let the index file handle any bad requests, since it already handles all the friendly URL requests and everything. This way you don't really need extra code in the index file. It will run normally and see 'somefile.php' and the page they're trying to open and determine that this is not a valid page to be opening and error out like any other invalid path, at least it would for the way mine is set up.

RewriteEngine On
RewriteBase /
RewriteRule .* index.php [L]

You would have to exclude any images or CSS folders if you don't use sub-domains for them like I do, or you can process them with the index file as well.

Example for excluding images and css folders:

RewriteRule !^(images|css)/.* index.php [L]

Or if you don't want to do that, you could send all the disallowed files to -.

RewriteRule !^(index\.php|images/.*|css/.*) - [L]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号