T
T
thenull32021-10-28 21:58:50
htaccess
thenull3, 2021-10-28 21:58:50

How to correctly implement a subdomain directory in .htaccess?

There is such an entry in .htaccess:

# /admin/-> admin.site.com
RewriteRule ^admin - [L]
RewriteCond %{HTTP_HOST} (www.)?admin.site.com [NC]
RewriteRule (.*) admin/$1 [L]

The subdomain itself has connected and is accessible via admin.site.com, everything opens, but... I create another test

folder in the admin folder and the index.php file in it ; I go to admin.site.com/test (without putting a slash at the end) and it throws me to admin.site.com/admin/test/ . If you go to admin.site.com/test/ (this time putting a slash at the end) - there will be no redirect to admin.site.com/admin/test/ at all. I tried with crutches in php, like with if ($_SERVER['REQUEST_URI'] == '/admin/')... and there is an error 404. I added redirects with a slash at the end to the .htaccess folder admin :





RewriteEngine On
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} !\/$
RewriteRule ^(.*[^\/])$ /$1/ [R=301,L]

Everything works, but it's very crooked. For example, I can enter admin/ through the main domain and I will get a 404 error, or I can enter admin/test/ and I will be transferred to test/ .

What is the problem and how to fix it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question