2016-08-01 60 views
0

我有一個在Apache服務器託管的URL「http://10.21.50.66:8123/test/file/index.htm」。我想將網址縮短爲「http://10.21.50.66:8123/」,我設法通過在httpd.conf中使用重寫功能來實現。然而,當我在瀏覽器中鍵入「http://10.21.50.66:8123/」,它會重定向和瀏覽器的URL將變回長的URL「http://10.21.50.66:8123/test/file/index.htm」。我想歸檔的是,當我每次在瀏覽器中鍵入「http://10.21.50.66:8123」,瀏覽器將打開「http://10.21.50.66:8123/test/file/index.htm」,但在瀏覽器的URL仍將呈現「http://10.21.50.66:8123/」。以下是燃燒設置:關於Apache的重寫功能,縮短URL

RewriteEngine On 

RewriteRule ^/$ http://10.21.50.66:8123/test/file/index.htm [R,L] 

任何想法?

在此先感謝。

回答

1

如果使用[R],Apache的返回響應碼302到瀏覽器(帶有新位置),這將導致新的URL出現在地址欄中。

嘗試:

RewriteEngine On 
RewriteRule ^/$ /test/file/index.htm [L] 
0

您需要在httpd.conf中創建一個虛擬主機。你可能會在extras文件夾中找到它也爲httpd.vhosts.conf它是這樣的:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName test.com 
    ServerAlias www.test.com 
    DocumentRoot /var/www/test.com/public_html 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

你需要寫類似:

<VirtualHost 10.21.50.66:8123> 
    ServerAdmin [email protected] 
    ServerName test.com 
    ServerAlias www.test.com 
    DocumentRoot [path to your test/file folder] 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost>