如何实现动态子域codeigniter用的.htaccess?

编程入门 行业动态 更新时间:2024-10-18 16:46:53
本文介绍了如何实现动态子域codeigniter用的.htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我如何能实现 codeigniter 动态子域与的.htaccess ?

How can I implement dynamic subdomains in codeigniter with .htaccess?

推荐答案

请确保子域在您的网站启用。当你进入test.yoursite它应该带你到你的网站的欢迎页面。相反,如果它使DNS查找错误,那么就意味着子域在您的网站未启用。

Make sure that subdomains are enabled on your site. When you enter test.yoursite 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 条目添加到DNS区域记录。

To enable subdomains on your site add *.yoursite 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 ^(.*)$ yoursite/$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 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 /#访问的所有网站的URI,而不是 www.yoursite /#。但是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/# URI instead of www.yoursite/#. But the URIs are not pretty and there would be more than one way to access a URI.

所以,如果你使用上面的规则,它会给你的 pretty的URI的,更重要的是,会给您唯一的URI 。所以,如果你使用上面的规则,你将只能得到一个URI的注册页面,这是 yoursite/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 yoursite/signup.

更多推荐

如何实现动态子域codeigniter用的.htaccess?

本文发布于:2023-10-31 16:07:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何实现   动态   htaccess   codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!