【问题标题】:CodeIgniter: How to properly setup htaccess for domain forwarding to a subdirectory of a subdomain?CodeIgniter:如何正确设置 htaccess 以将域转发到子域的子目录?
【发布时间】:2014-01-21 14:33:37
【问题描述】:

我在子域的子目录中设置了 CodeIgniter。我的 htaccess 文件适用于以下内容:http://subdomain.domain.com/subdirectory/

工作的 htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase /subdirectory/


RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)

RewriteRule ^(.*)$ index.php?/$1 [L]

但是,当我将域名 http://www.mydomainname.org 指向 public_html/subdirectory 时,这不起作用。

我想要实现的是我想使用http://www.mydomainname.org/whatever/ 来掩盖http://sub.domain.com/subdirectory/index.php/whatever

这可能吗?有什么我可以添加到我的 htaccess 中来实现这一点的吗?

我尝试使用 htaccess 答案 here,但没有运气。

【问题讨论】:

    标签: php .htaccess codeigniter mod-rewrite


    【解决方案1】:

    我认为如果你想同时工作,你需要为主机名添加额外的条件,尝试类似:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    
    # for main domain
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomainname\.com$ [NC]
    RewriteRule ^$ /index.php [L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomainname\.com$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    # for subdomain
    RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
    RewriteRule ^$ /subdirectory/index.php [L]
    
    RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
    RewriteRule ^(?:subdirectory/|)(.*)$ /subdirectory/index.php?/$1 [L]
    

    【讨论】:

    • 我现在只有在尝试转到:mydomain.org/whatever 时才会收到 404 错误,但如果我使用 domain.org/index.php/whatever,这仍然有效。
    • @Ryan 嗯,尝试从 RewriteRule ^(.*)$ /index.php?/$1 [L] 行中删除 ?
    • 我还有一个没有 ? 的 404
    • 错误就在我这边。我的域名有错字。非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 2023-03-06
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2014-03-08
    相关资源
    最近更新 更多