Creating a subdomain from a folder, but denying access to the folder

Well, I spent almost 4 hours searching a site for a solution, and another 2 hours searching Google, which is not very useful when most sites copy data. So I decided to ask for a little help.

I created the subdomain successfully, say http://admin.myhost.com, which basically takes data from a folder admin. The problem is that when I put the http://myhost.com/adminscripts are still available. Let's say I want to make this folder inaccessible by transferring the redirection to a user file, for example index.php?template=error404, when some file is executed via url http://myhost.com/admin. I added this line to.htaccess

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

and everything turned out 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]

, .htaccess ( RewriteEngine), , http://admin.myhost.com http 500, , .htaccess , RewriteEngine, , , URL, /admin

. - ? - ?

+4
1

/admin/.htaccess :

RewriteEngine On

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

/index.php?template=error404,

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

Source: https://habr.com/ru/post/1523630/


All Articles