Har*_*nan 0

确保您的网站上启用了子域。当您输入 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>
Run Code Online (Sandbox Code Playgroud)

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

重要的提示:

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

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