How to create dynamic subdomains in codeigniter with htaccess

放肆的年华 提交于 2019-12-11 11:52:26

问题


am using codeigniter, I want to set up .htaccess to make dynamic subdomains. And I cannot figure out how. I am trying to create custom domain names using .htaccess

Currently my URL looks like this:

http://www.example.com/public/stores/shop/products

I need it to look like this:

http://www.shop.example.com/public/stores/products

but it throws a 404?

stores - controller name, shop - dynamic name

The problem is that each shop should get a sub-domain automatically.Would be great if you could share the work around for the code & the .htaccess

I tried this code:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /

   RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
   RewriteCond %{REQUEST_URI} ^/$
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).example.com [NC]
   RewriteRule (.*) /index.php/controller/function/%2 [P]

   RewriteCond $1 !^(index\.php|images|robots\.txt|css|js)
   RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

Thanks in advance.

来源:https://stackoverflow.com/questions/24488576/how-to-create-dynamic-subdomains-in-codeigniter-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!