我想我的域名是"www.domain.com"我有一个文件系统
public_html
|----ds
|--application
|--cache
|--controller
...
|--css
|--image
|--system
|--index.php
|----zs
|----fd
public_html是根目录。
我在。haccess中使用有条件this::
1) ds目录为子域。当URL为ds.domain.com时。它映射的文件路径在www.domain.com/ds/index.php/
2)我想清理URL表单www.domain.com/ds/index.php/translate/paintext(示例完整的URL)到ds.domain.com/translate/paintext(干净的URL)
如何在。haccess中编码
/********************************************************************/
我把。haccess放在/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]
怎么了??
至少有一件事是错误的是你的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"部分的新URL,你需要一个新的规则来做到这一点:
RewriteCond %{THE_REQUEST} ' /+index'.php/
RewriteRule ^index.php/(.*)$ /$1 [L,R=301]