我正在使用Cakephp框架2.2.2。URL重寫在cakephp中創建子域
我想爲用戶創建一個個性化的URL。例如,如果用戶輸入用戶名= pragnesh, 那麼他們可以訪問我的網站,如:http://pragnesh.mylocalhost.com,相同blinksale.com
我的URL:http://mylocalhost.com/test/users/front_home
我想http://test.mylocalhost.com/users/front_home
我的URL:http://mylocalhost.com/test/setting/pages在訪問http://test.mylocalhost.com/setting/pages
任何網址: 可以訪問http://test.mylocalhost.com/xxxxx/xxxxx
OR
: http://mylocalhost.com/test/xxxxx/xxxxx
可以在訪問
網址:http://mylocalhost.com/users/front_home?site=test
我想在訪問它:http://test.mylocalhost.com/users/front_home
我的URL:http://test.mylocalhost.com/setting/pages
任何網址:http://mylocalhost.com/setting/pages?site=test
可以訪問http://mylocalhost.com/xxxxx/xxxxx?site=test
可以訪問:http://test.mylocalhost.com/xxxxx/xxxxx
我的問題可能是My cakephp 2.2 site not working on subdomain 可能重複,但沒有答案公佈。
我在嘗試下面的代碼\程序\ 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
什麼是您的測試子域的DocumentRoot?你是否也可以從Apache配置文件中發佈'test'子域的'VirtualHost'條目? – anubhava 2014-10-13 06:43:16
文檔根目錄是mylocalhost,我無法訪問主機文件 – 2014-10-13 06:59:50
'DocumentRoot'需要是完整的文件系統路徑,並且您需要知道確切的'DocumentRoot'用於根域和'test'子域。 – anubhava 2014-10-13 07:01:24