已经有一段时间了!
大家好,
所以我试图实现以下目标:
www.domain.com
domain.com -> 301 -> www.domain.com
account-name.domain.com -> mask and ask server for -> domain.com/account/acount-name
account-name.domain.com/page -> mask and ask server for -> domain.com/account/account-name/page
etc..
到目前为止,我已经在我的htaccess中得到了这个:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ account/%1$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
但是我一直收到这种403消息,它看起来像一个循环!
您无权访问 /index.php/account/testindex.php/account/testindex.php/account/testindex.php/account/testindex.php/account/test
也许我错过了一些显而易见的事情,因为我已经做了一段时间并且在上次尝试时放弃了。它甚至可能吗?
我的下一个挑战是......
一旦我对此进行了排序,我计划允许用户设置CNAMES
并指向我们的domain.com,我希望能够将非domain.com请求重写为类似于上述结构的内容,如果不一样,因为我们显然可以使用正则表达式测试域格式,然后从数据库加载帐户。所以对此的任何建议都是奖励:)
设置
目前在Apache和Ubuntu 14 Server上使用Codeigniter。
感谢先进的任何指导!
-Stefan
答案 0 :(得分:0)
尝试更改
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
到
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
L
确保此重写是此请求的最后一个处理规则。否则Apache也会应用你的其他重写规则,导致这个:
/index.php/account/testindex.php/account/testindex.php/account/testindex.php/account/testindex.php/account/test