mod_rewrite 用于(子)域和 cakephp 的错误网址
我在主机上将我的域重写到他们的文件夹中:
www.domain.com -> domains/domain.com/www
我在文档根目录中使用以下 htaccess
Options +FollowSymLinks +Indexes
RewriteEngine On
# www->non-www
RewriteCond %{HTTP_HOST} ^www\.([a-z0-9-.]+)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,QSA,L]
# www
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.([a-z]+)$ [NC]
RewriteCond $0 !^domains/
RewriteRule (.*) /domains/%1.%2/www/$1 [L]
#non-www
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.([a-z0-9-]+)\.([a-z]+)$ [NC]
RewriteCond $0 !^domains/
RewriteRule (.*) /domains/%2.%3/%1/$1 [L]
一切正常,但 cake 创建了错误(丑陋)的网址。它可以工作,但是...
在domain.com上运行的cakephp 2.0包含$this->Html->link("/controller");。它创建指向 /domains/domain.com/www/controller 而不是 /controller 的链接。
I'm on hosting where I'm rewriting my domains to their folders:
www.domain.com -> domains/domain.com/www
I'm using following htaccess in document root
Options +FollowSymLinks +Indexes
RewriteEngine On
# www->non-www
RewriteCond %{HTTP_HOST} ^www\.([a-z0-9-.]+)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,QSA,L]
# www
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.([a-z]+)$ [NC]
RewriteCond $0 !^domains/
RewriteRule (.*) /domains/%1.%2/www/$1 [L]
#non-www
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.([a-z0-9-]+)\.([a-z]+)$ [NC]
RewriteCond $0 !^domains/
RewriteRule (.*) /domains/%2.%3/%1/$1 [L]
Everything works but cake creates wrong (ugly) urls. It works but...
cakephp 2.0 running on domain.com contains $this->Html->link("/controller");. It creates link to /domains/domain.com/www/controller instead of /controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,
使用app/config中的routes.php
这是蛋糕htaccess。如果你使用htaccess和routes.php,我想你会重写你的链接两次......
例如:
你可以像htaccess一样配置你的路由
该路线的路径:
您还可以在路线中添加参数(用于编辑或其他)
这里有所有路线手册
如果您还有其他问题,请继续!
Hy,
Use routes.php from app/config
It's cake htaccess. If you use htaccess and routes.php you rewrite your link twice i think...
For example:
You can configure your routes like an htaccess
The path for this route:
Also you can add params in a route (for editing or something else)
Here you have all routes manual
If you have another question, go ahead!