M
M
Maxim2014-05-07 19:04:36
Yii
Maxim, 2014-05-07 19:04:36

How to solve the problem with dynamic subdomains?

The situation is this, the site has a bunch of dynamic subdomains, like username.site.com, they are all processed by one yii application using mod_rewrite:

RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.site\.com$ [NC]
RewriteRule (.*) index.php?un=%2 [NC,QSA]

Everything would be fine, but being on a subdomain, when accessing any other script other than index.php, no access occurs.
For example: if you click on the link alien.site.com/go.php when you are on alien.site.com, you will access index.php, as well as with any other scripts. How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaxHero, 2014-05-08
@go3l337

A couple of years ago, a similar question was asked on the Russian-language yii forum. I described the solution to a similar problem in this topic .
Briefly
apache virtualhost settings:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "D:/Projects/WWW/urlShortener"
    ServerName urlshortener.localdomain
    ServerAlias *.urlshortener.localdomain
    ErrorLog "logs/urlShortener.localdomain-error.log"
    CustomLog "logs/urlShortener.localdomain-access.log" common

    <Directory />
        DirectoryIndex index.php
    </Directory>
</VirtualHost>

mod_rewrite:
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

as well as CUrlManager rules:
array(
    'http://<user:\w+>.example.com/<lang:\w+>/profile' => 'user/profile',
)

L
lnked, 2014-05-07
@lnked

This is how my subdomains work

RewriteCond %{REQUEST_URI} !^/
RewriteRule ^(www\.)?([a-zA-Z0-9_/\-]*)\.site\.com(.*) /$2/%{REQUEST_URI} [L]
RewriteRule ^([a-zA-Z0-9_/\-]*)$ index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question