S
S
Sergey Prosvirin2014-02-18 11:32:28
Apache HTTP Server
Sergey Prosvirin, 2014-02-18 11:32:28

How to implement a subdomain redirect to a site section via .htaccess?

It is necessary to make sure that when visiting user.example.com, the page example.com/user opens, but not just redirects to this address, but that the subdomain address remains in the browser.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Prosvirin, 2014-02-18
@PraS

I do this, but the address in the browser changes to site.com/user
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^user.site.com [NC]
RewriteRule ^/(.*)$ /user/$1 [L]

V
Viktor Koreysha, 2014-02-18
@Iktash

And it is impossible to configure virtual host normally?

O
Oleg Prilepa, 2014-02-18
@OAPrilepa

I did this, placed the rule at the root:

RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^coffee.
    RewriteRule ^(.*)$ /projects/coffee/www/$1 [L]

And in the folder /projects/coffee/www/ put the rule:
RewriteEngine on
RewriteRule ^$                        index.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      index.php?id=$1  [QSA,L]

A
Alexander Skutin, 2014-02-18
@skutin

I did it like this, you put the necessary directories in the subdomains directory, and the request from the subdomains goes to the appropriate one.

<IfModule mod_rewrite.c>
  RewriteEngine on

  # Subdomains
  RewriteCond %{REQUEST_URI} !^/subdomains
  RewriteCond %{HTTP_HOST} ^(.*)\.domain\.ru$
  RewriteRule ^(.*)$ /subdomains/%1/$1 [L,QSA]
</IfModule>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question