Answer the question
In order to leave comments, you need to log in
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]
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question