V
V
Vitaly Meshcheryakov2015-10-27 13:21:27
Apache HTTP Server
Vitaly Meshcheryakov, 2015-10-27 13:21:27

Internal redirect without rewrite. How to do it in .htaccess?

There is a site for example site.ru. Configured dns and apache for dynamic subdomains.
Added a rule to .htaccess -
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.site\.ru [NC]
RewriteRule (.*) new.site.ru/admin [L]
RewriteCond %{HTTP_HOST} ^(.+ )\.site/? [NC]
RewriteRule (.*) site.ru [L]
After that everything worked as follows. If you enter any subdomain from the bulldozer, everything sends to ch. site page.
If you type sub.site.ru before it redirects to new.site.ru/admin/.
But the task was the following, so that when you type sub.site.ru you should redirect to new.site.ru/adminBUT sub.site.ru should remain in the address bar of the browser and, accordingly, all requests for sub.site.ru/afisha (for example) should work.
Is it possible to do all this in htacces or should I dig the other way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Meshcheryakov, 2015-10-28
@unitours

Thanks for the answer! Decided as follows.
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^sub\.site\.ru$ [NC]
RewriteCond %{REQUEST_URI} !^/sub
RewriteRule ^(.*) %{HTTP_HOST}$1
RewriteRule ^(.*)\.site\ .ru(.*) admin/$1/$2
Now it opens perfectly - by sub.site.ru - site.ru/admin and in the address bar as before sub.site.ru. That is, empty requests worked as they should. But now it is necessary that, for example, site.ru/afisha opens on sub.site.ru/afisha, and site.ru/admin/afisha opens. I'll try to do as Vadim Nazarov wrote in the post above. And what exactly should be written in this route.php?
Everything was solved in htaccess - as follows. RewriteCond %{HTTP_HOST} ^(.+)\.site\.ru$ [NC] RewriteCond %{REQUEST_URI} !^/(.+)
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^(.*) %{HTTP_HOST}$1
RewriteRule ^sub\.site\ .ru(.*) admin/

V
Vadim Nazarov, 2015-10-28
@nvadim

And subdomains with one dokrut?
In this case, it is necessary that some file, for example, route.php, is responsible for routing requests.
Next write:
RewriteRule . route.php
All requests must go through this file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question