如何实现动态子域codeigniter用的.htaccess? [英] How to implement dynamic subdomains in codeigniter with .htaccess?
问题描述
我如何能实现 codeigniter
动态子域与的.htaccess
?
How can I implement dynamic subdomains in codeigniter
with .htaccess
?
推荐答案
请确保子域在您的网站启用。当你进入test.yoursite.com它应该带你到你的网站的欢迎页面。相反,如果它使DNS查找错误,那么就意味着子域在您的网站未启用。
Make sure that subdomains are enabled on your site. When you enter test.yoursite.com it should take you to the welcome page of your site. If instead it gives DNS lookup error then it means subdomains is not enabled on your site.
要启用您的网站的子域 *。yoursite.com
条目添加到DNS区域记录。
To enable subdomains on your site add *.yoursite.com
entry to the DNS Zone records.
二插入以下code在的.htaccess
文件,并替换 yoursite
适当。
Second insert the following code in your .htaccess
file and replace yoursite
appropriately.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#codeigniter specific rule
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#codeigniter specific rule
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#this rule removes www from the URL if its used
RewriteCond %{HTTP_HOST} ^www.
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
#the auth system URIs which don't have subdomains
RewriteCond %{HTTP_HOST} ^yoursite.
RewriteRule ^(signup|signin|forgot_password)/?$ index.php?/auth/$1 [L]
#this rule handles the subdomains
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).yoursite.com
RewriteRule ^(.*)$ index.php?/public_site/%1/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
添加更多的规则,如果需要的话,用于处理身份验证系统或子域。我知道我做了我的网站获得pretty的URI的。
Add more rules, if necessary, for handling auth system or subdomains. I know I did for my site to get pretty URIs.
我发现,在默认情况下的子域的URI的工作非常好,codeigniter没有任何上述规则。你可以用 test.yoursite.com /#
访问的所有网站的URI,而不是 www.yoursite.com /#
。但是URI并不pretty的和将有访问的URI的方法不止一种。
I found that by default the subdomain URIs work very well with codeigniter without any of the above rules. You can access all of your site with test.yoursite.com/#
URI instead of www.yoursite.com/#
. But the URIs are not pretty and there would be more than one way to access a URI.
所以,如果你使用上面的规则,它会给你的 pretty的URI的,更重要的是,会给您唯一的URI 。所以,如果你使用上面的规则,你将只能得到一个URI的注册页面,这是 http://yoursite.com/signup
。
So if you use the above rules it will give you pretty URIs and, more importantly, will give you unique URIs. So if you use the above rules you will only get one URI for the signup page and that is http://yoursite.com/signup
.
这篇关于如何实现动态子域codeigniter用的.htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!