Y
Y
yoursmileua2015-11-16 21:25:02
CodeIgniter
yoursmileua, 2015-11-16 21:25:02

Redirect to dynamic subdomain from folder?

Hello, about 7 o'clock in a complete stupor. Tried a bunch of google solutions from the search !!!!
There is a site like infoumnik.local/sub/user1 where sub and user1 are folders.
User1 contains index.php file
Trying to access user1 folder via user1.infoumnik.local subdomain via mode_rewrite
(SOLUTION BELOW)
Configured httpd.conf as follows:

<VirtualHost *:80>
DocumentRoot    "c:/openserver/domains/infoumnik.local"
ServerName      "infoumnik.local"
ServerAlias     "infoumnik.local" "*.infoumnik.local" 
ScriptAlias     /cgi-bin/ "c:/openserver/domains/infoumnik.local/cgi-bin/"
</VirtualHost>

<VirtualHost *:443>
DocumentRoot    "c:/openserver/domains/infoumnik.local"
ServerName      "infoumnik.local"
ServerAlias     "infoumnik.local" "*.infoumnik.local" 
ScriptAlias     /cgi-bin/ "c:/openserver/domains/infoumnik.local/cgi-bin/"

SSLEngine    on

SetEnvIf User-Agent ".*MSIE [1-5].*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

SetEnvIf User-Agent ".*MSIE [6-9].*" \
ssl-unclean-shutdown
</VirtualHost>

hosts file added the following
127.0.0.1     infoumnik.local
127.0.0.1     user1..infoumnik.local
127.0.0.1     user2.infoumnik.local
127.0.0.1     user3.infoumnik.local


The hosts file opened the ability to switch to a subdomain like
user1.infoumnik.local
user2.infoumnik.local
user3.infoumnik.local
in response, I get the address user1.infoumnik.local and display the index infoumnik.local

in .htaccess I write the following:
AddDefaultCharset off
# Устанавливаем страницу для ошибки 404
ErrorDocument 404 /index.php
 
# Устанавливаем индексный файл для директории
DirectoryIndex index.php
 
# Определяем правила для модуля mod_rewrite
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_HOST} !^www\.infoumnik\.local$
RewriteCond %{HTTP_HOST} (www\.)?(.*)\.infoumnik\.local$
RewriteCond %{REQUEST_URI} !sub/
RewriteRule ^(.*)$ sub/%2/$1
 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
 
</IfModule>



Everything worked fine now
I have access to the index file which is located in the user1 folder at user1.infoumnik.local without going into the hosts file every time. And which hoster supports this feature?

As far as I know, in hosting Ukraine you need to create subdomains manually.

I'm doing it on an OpenServer virtual server
:(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Fedoseev, 2015-11-16
@martin74ua

VirtualDocumentRoot /var/www/user/data/www/%0
implements automatic selection for a site of a directory like
/var/www/user/data/here_full_site_name
This is from the virthost config in Apache.
Look at the examples in the documentation, it may help in your desires.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question