从文件夹创建子域,但拒绝文件夹访问

时间:2022-04-07 06:32:14

Okay, I've spent almost 4 hours searching the site for a solution, and another 2 hours searching google, wich is not quite useful when most sites copy paste the data. So here I decided to ask for a little help.

好吧,我花了将近4个小时在网站上搜索解决方案,另外2个小时搜索谷歌,当大多数网站复制粘贴数据时,这并不是很有用。所以在这里我决定寻求一些帮助。

I created a subdomain successfully, let's say http://admin.myhost.com, wich basically take the data from the folder admin. The problem is that when I put http://myhost.com/admin the scripts are still accessible. Let's say I want to make this folder unaccessible, throwing a redirect to a custom file, for example index.php?template=error404 when some file is executed via the url http://myhost.com/admin. I've added this line to the .htaccess

我成功创建了一个子域名,让我们说http://admin.myhost.com,它基本上从文件夹admin获取数据。问题是,当我放入http://myhost.com/admin时,脚本仍可访问。假设我想让这个文件夹无法访问,重定向到自定义文件,例如index.php?template = error404当某个文件通过URL http://myhost.com/admin执行时。我已将此行添加到.htaccess中

RewriteRule ^admin(.*) /index.php?template=error404 [L]

and it ended up like this.

它就像这样结束了。

Options +FollowSymlinks

Options -Indexes

<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>

RewriteEngine On

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?map=google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?map=google_base [L]
RewriteRule ^download(.*) /index.php?template=error404 [L]
RewriteRule ^admin(.*) /index.php?template=error404 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?seo_url=$1 [L,QSA]

It actually works only if I delete the empty .htaccess on the admin folder (It only says RewriteEngine on), but when I do that, the site http://admin.myhost.com throws an http error 500, and it is not accessible anymore. If I add again the .htaccess on the admin folder stating the RewriteEngine on rule, the subdomain starts to work again, but again, the folder is accessible via URL adding /admin

它实际上只有在我删除admin文件夹中的空.htaccess时才会起作用(它只会说RewriteEngine on),但是当我这样做时,网站http://admin.myhost.com抛出一个http错误500,它不是再也无法访问。如果我再次添加管理文件夹中的.htaccess,说明规则上的RewriteEngine,则子域再次开始工作,但同样,该文件夹可通过URL添加/ admin访问

I can't seem to find the solution to this problem after several hours. Is there any way to do this? Am I doing something wrong?

几个小时后我似乎无法找到解决这个问题的方法。有没有办法做到这一点?难道我做错了什么?

1 个解决方案

#1


5  

In the /admin/.htaccess have this rule:

在/admin/.htaccess中有这个规则:

RewriteEngine On

# block access if HOSTNAME is not starting with admin.    
RewriteCond %{HTTP_HOST} !^admin\. [NC]
RewriteRule ^ - [F]

OR if you want to show /index.php?template=error404 then

或者如果你想显示/index.php?template=error404那么

RewriteCond %{HTTP_HOST} !^admin\. [NC]
RewriteRule ^ /index.php?template=error404 [L,QSA]

#1


5  

In the /admin/.htaccess have this rule:

在/admin/.htaccess中有这个规则:

RewriteEngine On

# block access if HOSTNAME is not starting with admin.    
RewriteCond %{HTTP_HOST} !^admin\. [NC]
RewriteRule ^ - [F]

OR if you want to show /index.php?template=error404 then

或者如果你想显示/index.php?template=error404那么

RewriteCond %{HTTP_HOST} !^admin\. [NC]
RewriteRule ^ /index.php?template=error404 [L,QSA]