G
G
geektimer2018-09-25 03:20:48
Yii
geektimer, 2018-09-25 03:20:48

How to set up routing in Yii2 for a subdomain?

Hello!
I just started working with Yii 2 and I'm stuck on configuring .htaccess
Now the project is loaded at this address `mydomain.com`, but I want to make a separate subdomain for it and a directory like this `spec.mydomain.com/dev`
I have separated backend and frontend in the project and now htaccess looks like this:

# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on

#RewriteCond %{ENV:HTTPS} !on
#RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#RewriteCond %{HTTP_HOST} ^admin\.(.*)$ [NC]
#RewriteRule ^(.*)$ /backend/web/$1 [L]

RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1

# www.site.com -> site.com
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Please tell me what needs to be done so that the subdomain and the subsequent dev directory and site links are processed correctly. I just can’t get Yii on a subdomain, there is not enough information. Maybe it's still in the Yii routing itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kulay, 2018-09-25
@Kulay

In the settings of the domain itself, specify the subdomain spec.mydomain.com (this is on the service where the domain is registered). Then, on the server, configure apache (nginx, etc.) to this subdomain. After that, you throw the site into the dev directory of the root directory of this subdomain and everything should start. Don't forget to restart apache (nginx etc).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question