doubi7739 2012-11-20 14:00
浏览 141

如何将子文件夹设置为root并限制某些访问权限

I read an article on my host on how to set a subfolder as the root of my domain, but it misled me into believing requests would all be sent to the /subfolder/ and not at all to the root, and that was not the case.

I'm using this code in .htaccess in the root and unfortunately, it's not working as desired.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$

RewriteCond %{REQUEST_URI} !^/subfolder/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /subfolder/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

What I'm trying to achieve is the following:

  • Root in /subfolder/
  • All requests to the original true root being denied as if it didn't exist at all. Such as phpinfo.php, php.ini, any page or miscellaneous item in there being denied access by the error handling set in the /subfolder/. Any request to "domain.com/whateverhere" absolutely always sent to /subfolder/.
  • If possible, restrict any ability to go to domain.com/subfolder/ to show a 404. I suppose a redirect is equally effective though.
  • I currently use a /resources/ folder in the root which is at domain.com/resources/ which contains scripts, css, images, etc. and even though the rewrite is in place to set the /subfolder/ to root, requests to domain.com/resources/ are still being accepted even though it's not in the /subfolder/. As I said before, I'd like to know how I can truly restrict any access to the true root, and force all requests to the /subfolder/.

All in all, I'd like the "root" to be completely set as the /subfolder/, have important files like phpinfo.php and php.ini in the actual root inaccessible, and still use .htaccess in the true root as usual.

I know I'm asking a lot here, so I apologize heh.

Thank you in advance to anyone who can assist.

  • 写回答

1条回答 默认 最新

  • douxu3732 2012-11-20 14:09
    关注

    You can add a .htpasswd file to your subfolder:

    .htpasswd

    admin:$apr1$EvV5M50w$9IgAqskEg5r2pIIXUzQyp0
    

    And define it in your subfolder/.htaccess file like this:

    AuthUserFile /www/site/.htpasswd
    AuthType Basic
    AuthName "My secret place"
    require valid-user
    

    Now opening your subfolder, you will be asked far a password and a username ( admin / admin in my example ).

    And to set it as the starting folder, you can always just add

    <?php header( 'Location: /subfolder/' ); die; ?>
    

    at the very top of your index.php file, so it will always redirect you to the subfolder.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)