在codeigniter中mod_rewrite子域和clen url

时间:2014-08-05 20:22:49

标签: php .htaccess codeigniter

我想我的域名是“www.domain.com” 我有一个文件系统

public_html
   |----ds
        |--application
            |--cache
            |--controller
                 ...

        |--css
        |--image
        |--system
        |--index.php
   |----zs
   |----fd

public_html是根目录。

我在.htacess中编码,条件为::

1)ds目录是子域名。当URL是ds.domain.com时。它在www.domain.com/ds/index.php /

中映射文件路径

2)我想将网址www.domain.com/ds/index.php/translate/paintext(示例完整网址)清理为ds.domain.com/translate/paintext(clean url)

如何在.htacess中编码?

/ ************* ******** /

我将.htacess放在/ ds文件夹中并尝试编码:

#subdomain to subdirectory
RewriteCond %{HTTP_HOST} ^www.domain.com/ds/
RewriteRule ^(.*)$ http://ds.domain.com/$1 [L,R=301]    

#clean URL from codeigniter 
RewriteCond $1 !^(index\.php|lib|css|image)
RewriteRule ^(.*)$ index.php/$1 [L]

有什么问题?

1 个答案:

答案 0 :(得分:0)

至少有一件事是你的HTTP_HOST。该变量是主机名,主机名中不包含URL路径信息。因此www.domain.com/ds/永远不会作为主机名存在。将其更改为:

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^ds/(.*)$ http://ds.domain.com/$1 [L,R=301]    

第二个问题看起来不错。但是,如果您想/index.php的请求重定向到一个没有" index.php"的新网址。部分,你需要一个新的规则来做到这一点:

RewriteCond %{THE_REQUEST} \ /+index\.php/
RewriteRule ^index.php/(.*)$ /$1 [L,R=301]
相关问题