duanfei8149
duanfei8149
2015-09-26 20:08

如何使用.htaccess文件限制PHP文件访问?

已采纳

Here is my .htaccess file

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?r=$1 [QSA,L]

My base folder contains one "index.php" file and "app" folder and the app folder contains some php files and i don't want to direct access these php files inside app folder using browser.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongzhuo8210 dongzhuo8210 6年前

    As worked out in the comments to your question your requirements are actually a little more complex than what you wrote in your question.

    I guess this is what you are actually looking for:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteRule ^(.*)$ index.php?r=$1 [QSA,L]
    

    This will rewrite requests to index.php when the file name in the request ends in the .php file name extension.

    点赞 评论 复制链接分享

相关推荐