gpt4 book ai didi

.htaccess - 如何使用.htaccess在codeigniter中实现动态子域?

转载 作者:行者123 更新时间:2023-12-03 05:46:26 24 4
gpt4 key购买 nike

如何使用 .htaccesscodeigniter 中实现动态子域?

最佳答案

确保您的网站上启用了子域。当您输入 test.yoursite.com 时,它应该会将您带到站点的欢迎页面。如果相反,它给出 DNS 查找错误,则意味着您的网站上未启用子域。

要在您的网站上启用子域,请将 *.yoursite.com 条目添加到 DNS 区域记录中。

然后将以下代码插入到您的 .htaccess 文件中,并适本地替换 yoursite

<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>

如有必要,添加更多规则来处理身份验证系统或子域。我知道我为我的网站获得了漂亮的 URI。

重要说明:

我发现默认情况下,子域 URI 与 codeigniter 配合得很好,无需任何上述规则。您可以使用 test.yoursite.com/# URI 而不是 www.yoursite.com/# 访问您的所有网站。但 URI 并不漂亮,并且访问 URI 的方法不只一种。

因此,如果您使用上述规则,它将为您提供漂亮的 URI,更重要的是,将为您提供唯一的 URI。因此,如果您使用上述规则,您将只能获得一个注册页面 URI,即 http://yoursite.com/signup

关于.htaccess - 如何使用.htaccess在codeigniter中实现动态子域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9732366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com