使用域作为“前缀”在 CakePHP 上

发布于 2024-09-28 22:10:26 字数 744 浏览 2 评论 0原文

假设我有一个运行 CakePHP 的站点,并且有前缀“product”。

我有很多页面的 URL 如下:

http://mysite.com/produt/blue-shirt/details
http://mysite.com/produt/blue-shirt/order
http://mysite.com/produt/skate/details
http://mysite.com/produt/sun-glasses/vendors

现在我需要使用像 http://mysite-blue-shirt.com/ 这样的域作为 blue-shirt 产品的“快捷方式”,以及我的 URL会变成:

http://mysite-blue-shirt.com/details
http://mysite-blue-shirt.com/order

我需要做什么?

我认为这是网站根目录下 app 目录之外的 .htaccess 的问题。

这是当前的语法:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Let's say that I have a site running CakePHP and I have the prefix "product".

I have lots of pages with URL like:

http://mysite.com/produt/blue-shirt/details
http://mysite.com/produt/blue-shirt/order
http://mysite.com/produt/skate/details
http://mysite.com/produt/sun-glasses/vendors

Now I need to use a domain like http://mysite-blue-shirt.com/ as "shortcut" to the blue-shirt product, and my URLs will become:

http://mysite-blue-shirt.com/details
http://mysite-blue-shirt.com/order

What I need to do?

I think that's something with the .htaccess on the root of the website, outside the app directory.

Here's the current syntax:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

萌酱 2024-10-05 22:10:26

试试这个:

<IfModule mod_rewrite.c>
   RewriteEngine on

   RewriteCond    %{HTTP_HOST} ^mysite-blue-shirt\.com
   RewriteCond    %{REQUEST_URI} !^/product/blue-shirt
   RewriteRule    ^(.*)$ app/webroot/product/blue-shirt/$1 [L]

   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

第一行检查站点的名称。第二个检查它是否尚未被重写为 blue-shirt。最后一行执行重写。

Try this:

<IfModule mod_rewrite.c>
   RewriteEngine on

   RewriteCond    %{HTTP_HOST} ^mysite-blue-shirt\.com
   RewriteCond    %{REQUEST_URI} !^/product/blue-shirt
   RewriteRule    ^(.*)$ app/webroot/product/blue-shirt/$1 [L]

   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

The first line checks the site's name. The second one checks if it has already not been re-written to blue-shirt. The final line carries out the rewrite.

初相遇 2024-10-05 22:10:26

我认为您需要创建自己的自定义路由类。检查这个: http://mark-story.com/帖子/视图/使用自定义路由类-in-cakephp

I think you'll need to create your own custom Routing class. Check this: http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp

甜心小果奶 2024-10-05 22:10:26

为了让外界看到这一点,您需要注册 mysite-blue-shirt 和所有其他变体。

For the outside world to see this you would need to register mysite-blue-shirt and all the other variants.

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