mod_rewrite 用于(子)域和 cakephp 的错误网址

发布于 2025-01-04 22:40:49 字数 762 浏览 1 评论 0原文

我在主机上将我的域重写到他们的文件夹中:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄离 2025-01-11 22:40:49

嘿,

使用app/config中的routes.php
这是蛋糕htaccess。如果你使用htaccess和routes.php,我想你会重写你的链接两次......

例如:

    Router::connect('/', array('controller' => 'your_controller', 'action' => 'your_actiom'));

你可以像htaccess一样配置你的路由
该路线的路径:

    http://your_domain.com/controller/action

您还可以在路线中添加参数(用于编辑或其他)

这里有所有路线手册

如果您还有其他问题,请继续!

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:

    Router::connect('/', array('controller' => 'your_controller', 'action' => 'your_actiom'));

You can configure your routes like an htaccess
The path for this route:

    http://your_domain.com/controller/action

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文