Estoy usando el framework Cakephp 2.2.2.
Quiero crear una URL personalizada para el usuario. Por ejemplo, si un usuario ingresa username = pragnesh , entonces pueden acceder a mi sitio como: http://pragnesh.mylocalhost.com , lo mismo que en blinksale.com
Mi URL: http://mylocalhost.com/test/users/front_home
Quiero acceder a él en: http://test.mylocalhost.com/users/front_home
Mi URL: http://mylocalhost.com/test/setting/pages
se puede acceder en: http://test.mylocalhost.com/setting/pages
cualquier URL: http://mylocalhost.com/test/xxxxx/xxxxx
se puede acceder en: http://test.mylocalhost.com/xxxxx/xxxxx
O
URL: http://mylocalhost.com/users/front_home?site=test
Quiero acceder a él en: http://test.mylocalhost.com/users/front_home
Mi URL: http://mylocalhost.com/setting/pages?site=test
se puede acceder en: http://test.mylocalhost.com/setting/pages
cualquier URL: http://mylocalhost.com/xxxxx/xxxxx?site=test
se puede acceder en: http://test.mylocalhost.com/xxxxx/xxxxx
Mi pregunta puede ser posible si el sitio de My cakephp 2.2 no funciona en el subdominio, pero no hay una respuesta publicada.
He intentado a continuación el código en \ app \ webroot.htaccess
htaccess subdomai (parte 2)
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]
Reescritura de URL para Subdominio
# 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]
pero ambos no funcionan para mí.
mi archivo raíz .htaccss es
RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L]
\ app.htaccess
RewriteEngine on RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L]
\ app \ webroot.htaccess
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L]
Host virtual en httpd.conf
DocumentRoot "E:/xampp/htdocs/bsale" ServerName mylocalhost.com ServerAlias *.mylocalhost.com Order allow,deny Allow from all
ARCHIVO HOST
127.0.0.1 mylocalhost.com 127.0.0.1 *.mylocalhost.com
Puede dejar su .htaccess como en el cakephp / .htaccess cakephp / app / .htaccess cakephp / app / webroot / .htaccess predeterminado.
Necesitará el host virtual como ahora tiene apuntando a su aplicación.
Lo que realmente necesita ver es la aplicación / Config / routes.php
Eche un vistazo a la línea que dice:
CakePlugin::routes();
Entonces, antes de ese momento, puedes hacer cualquier cosa que necesites (con rutas). Imaginemos que un usuario johndoe tiene http://johndoe.yourapp.com/
Obtenga el subdominio de la url, algo como esto:
array_shift((explode(".",'subdomain.my.com')));
utilizando:
$_SERVER['HTTP_HOST'] Router::connect('/users/front_home', array('controller' => 'users', 'action' => 'front_home', $yourSubDomain));
O simplemente deje el enrutador solo y detecte el subdominio en su AppController, y úselo en cualquier lugar de su aplicación.