且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CakePHP的子域与htaccess的

更新时间:2023-09-12 11:47:46

CakePHP的,几乎任何其他PHP框架解析$ _ SERVER ['REQUEST_URI']为了航线您的要求,以特定的控制器

CakePHP and almost any other PHP framework parse $_SERVER['REQUEST_URI'] in order to route your request to particular controller

更多信息: https://开头github.com/cakephp/cakephp/blob/2.6/lib/Cake/Network/CakeRequest.php#L230

所以你只需要具有相同的请求URI参数为您重定向得到应用工作。

so you simply need to have the SAME request URI parameters for your redirect to get app working.

有关旧的位置,这是/ admin的,对于新的位置应该是相同的,但你不希望通过它,所以***改变这样的任务:

For your old location it was "/admin", for new location it should be the same, but you do not want to pass it, so it is better to change the task like this:

当你去admin.site.com你将被重定向到site.com/admin~~V。

"When you go to admin.site.com you will be redirected to site.com/admin".

这可以简单地做过这样的:

This can be done simply like this:

重写规则^([^。] +)\\。例如\\ .COM http://example.com/$1

这不是规则的工作的例子,因为你还需要重写的子域的请求URI来得到的一切工作,这取决于你的需求,但可以水木清华这样的:

It is not a working example of rule because you also need to rewrite subdomain's request URI to to get everything working and it depends on your requirements, but can be smth like this:

重写规则^([^。] +)\\。例如\\ .COM(。*)http://example.com/$1/$2

UPD:真实的例子

$ cat app/webroot/.htaccess 
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteCond %{HTTP_HOST} ^admin.example.com
    RewriteRule ^(.*)$ http://example.com/admin/$1 [P,L,NC]
</IfModule>