I know there is millions of solution is available for redirect subdomain to directory. But still I am facing the problem.
I want to map subdomain in the following manner
I am using the following code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^demo1\.example\.com$
#RewriteCond %{REQUEST_URI} !^/demo1/
RewriteRule (.*) /demo1/$1 [L]
RewriteCond %{HTTP_HOST} ^demo2\.example\.com$
RewriteCond %{REQUEST_URI} !^/demo2/
RewriteRule (.*) /demo2/$1 [L]
</IfModule>
this is working fine but i am getting the dir name in url like demo1.example.com/demo1/ for this i have used the following rewrite rule
RewriteRule ^demo1/(.*)$ /$1 [L,NC,R]
but unable to remove demo1 from url i have codeigniter framework in demo1 dir having following htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
If you have a complete installation of the framework in each subdirectory and you're not doing any kind of dynamic mapping, then rewriting URLs isn't the best solution.
Just create a virtual host for each installation and set the server name accordingly.
<VirtualHost *:80>
DocumentRoot /var/www/example.com/demo1
ServerName demo1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example.com/demo2
ServerName demo2.example.com
</VirtualHost>
Depending on what kind of hosting you're using, you can create virtual hosts in your hosting management backend, or check the Apache 2.2 docs for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.