歡迎您光臨本站 註冊首頁

apache設置blog無限個二級域名,如何讓瀏覽器地址保持不變而不僅僅是跳轉一下?

apache的http.conf文件裡面這麼寫的:

<VirtualHost *:80>
DocumentRoot "E:/www/htdocs/blog"
ServerName *.xxx.com
ServerAlias *.xxx.com
RewriteEngine on
#RewriteLog       logs/rewrite.log
#RewriteLogLevel  3
RewriteCond %{HTTP_HOST} ^+\.xxx\.com$
RewriteCond %{HTTP_HOST} !^(www|bbs|news|blog)\.xxx\.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/(+)\.xxx\.com/?$ http://www.xxx.com/e/space?urlname=$1
#RewriteRule ^/(.*)$ /%{SERVER_NAME}/$1
</VirtualHost>

這樣就可以實現比如 輸入 ccc.xxx.com直接跳轉到http://www.xxx.com/e/space?urlname=ccc ,二級域名就實現了,問題是瀏覽器的地址也變了,這樣還是不能滿足要求,我想讓瀏覽器的地址不變,然後支持 比如輸入http://ccc.xxx.com/arc.htm直接跳轉到http://www.xxx.com/e/space?urlname=ccc?type=arc這樣的,這對優化很有利, 只是如何實現呢?據說要用反向代理,我測試幾次都沒有成功,盼望有實際使用經驗的人詳細說明下,謝謝;
《解決方案》

回復 #1 c123321 的帖子

我也和你遇到了相同的問題呀,在這裡一直得不到解決呀,高手們都休息了,呵呵
《解決方案》

不要用不同主機地址(HTTP_HOST)跳轉,
不能用
RewriteRule ^/(+)\.xxx\.com/?$ http://www.xxx.com/e/space?urlname=$1

只能用同一個 HTTP_HOST,下面的模式:
RewriteRule .* index.php

這樣地址就不會變了,然後在程序裡面使用
$_SERVER['HTTP_HOST'] 和 $_SERVER['REDIRECT_URL'] 2個變數,來獲得參數
比如:
$domain = explode('.', $_SERVER['HTTP_HOST'], 2);
$domain得到 urlname
然後通過 $_SERVER['REDIRECT_URL'] 來獲得更多的參數。
《解決方案》

我也來貢獻一下,經測試,這段代碼可用

RewriteCond %{HTTP_HOST} ^+\.5out\.com$
RewriteCond %{HTTP_HOST} !^(www|bbs|news|blog|sns15)\.5out\.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/(+)\.5out\.com/?$ http://sns15.5out.com/myspace.php?uname=$1


和樓主給的一樣,需要注意的是

1)被轉向的域名 sns15 需要在 RewriteCond %{HTTP_HOST} !^(www|bbs|news|blog|sns15)\.5out\.com$  中出現
2)apache需要打開代理模塊,  中的 P就是這個意思,如下:
  LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

-------------
原因:
'proxy|P' (force proxy)
This flag forces the substitution part to be internally forced as a proxy request and immediately (i.e., rewriting rule processing stops here) put through the proxy module. You have to make sure that the substitution string is a valid URI (例如,typically starting with http://hostname) which can be handled by the Apache proxy module. If not you get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map some remote stuff into the namespace of the local server.
注意:mod_proxy must be enabled in order to use this flag.

[火星人 ] apache設置blog無限個二級域名,如何讓瀏覽器地址保持不變而不僅僅是跳轉一下?已經有492次圍觀

http://coctec.com/docs/service/show-post-20885.html