[英]URL Rewrite create subdomain in cakephp
我正在使用Cakephp框架2.2.2。
我想为用户创建个性化的URL。 例如,如果用户输入username = pragnesh ,那么他们可以访问我的网站,如: http ://pragnesh.mylocalhost.com,与blinksale.com相同
我的网址: http : //mylocalhost.com/test/users/front_home
我想访问它: http : //test.mylocalhost.com/users/front_home
我的网址: http : //mylocalhost.com/test/setting/pages
可以访问: http : //test.mylocalhost.com/setting/pages
任何网址: http : //mylocalhost.com/test/xxxxx/xxxxx
可以访问: http : //test.mylocalhost.com/xxxxx/xxxxx
要么
网址: http : //mylocalhost.com/users/front_home?site = test
我想访问它: http : //test.mylocalhost.com/users/front_home
我的网址: http : //mylocalhost.com/setting/pages?site = test
可以访问: http : //test.mylocalhost.com/setting/pages
任何网址: http : //mylocalhost.com/xxxxx/xxxxx?site = test
可以访问: http : //test.mylocalhost.com/xxxxx/xxxxx
我的问题可能是我的cakephp 2.2网站没有在子域工作的重复,但没有发布答案。
我在\\ app \\ webroot.htaccess中尝试过以下代码
RewriteCond %{QUERY_STRING} !^([^&]*&)*site=[^&]+
RewriteCond %{HTTP_HOST} !^www\.mylocalhost.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+)\.mylocalhost.com
RewriteRule ^([^\.]*).php$ /$1.php?user=%1 [QSA,L,R]
# capture first part of host name
RewriteCond %{HTTP_HOST} ^([^.]+)\.mylocalhost\.com$ [NC]
# make sure site= query parameter isn't there
RewriteCond %{QUERY_STRING} !(^|&)site= [NC]
# rewrite to current URI?site=backererence #1 from host name
RewriteRule ^ %{REQUEST_URI}?site=%1 [L,QSA]
但两个都不适合我。
我的根.htaccss文件是
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
\\ app.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
\\程序\\ webroot.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
httpd.conf中的虚拟主机
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/bsale"
ServerName mylocalhost.com
ServerAlias *.mylocalhost.com
<Directory "C:/xampp/htdocs/bsale">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
主机文件
127.0.0.1 mylocalhost.com
127.0.0.1 *.mylocalhost.com
您可以将.htaccess保留为默认的cakephp / .htaccess cakephp / app / .htaccess cakephp / app / webroot / .htaccess
您将需要像现在这样的虚拟主机指向您的应用程序。
你真正需要看的是app / Config / routes.php
看一下这句话:
CakePlugin::routes();
所以,在那之前你可以做任何你需要的事情(有路线)。 让我们想象用户johndoe有http://johndoe.yourapp.com/
从网址获取子域名,如下所示:
array_shift((explode(".",'subdomain.my.com')));
使用:
$_SERVER['HTTP_HOST']
Router::connect('/users/front_home', array('controller' => 'users', 'action' => 'front_home', $yourSubDomain));
或者只留下路由器并检测AppController中的子域,并在应用程序的任何位置使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.