How to create dynamic subdomains in codeigniter wi

2019-08-11 05:30发布

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.

0条回答
登录 后发表回答