将域用作“前缀”;在CakePHP上 [英] Use domain as "prefix" on CakePHP
问题描述
比方说,我有一个运行CakePHP的站点,并且前缀为 product。
Let's say that I have a site running CakePHP and I have the prefix "product".
我有很多URL如下的页面:
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
现在我需要使用类似 http://mysite-blue-shirt.com/
作为蓝色衬衫产品的快捷方式,我的网址将变为:
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
我需要做什么?
我认为这与网站根目录上的 .htaccess
有关,在 app
目录之外。
I think that's something with the .htaccess
on the root of the website, outside the app
directory.
这是当前语法:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
推荐答案
尝试一下:
<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.
这篇关于将域用作“前缀”;在CakePHP上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!