2017-04-24 138 views
0

我正在使用與JBoss集成的Apache Web服務器「httpd-2.4.25-win64-VC14」。端口重定向工作正常。現在我想根據一些條件來替換URL,比如說,如果URL包含'Mobile',那麼我想用'Mobile/web'替換它並轉發它。根據條件Apache Httpd.conf重定向URL

爲此,我在<VirtualHost>標記中使用了<Directory>標記。現在,我發現的大多數在線參考文獻都在標記前加上了URL,例如'var/www/example',但我想根據localhost重定向,因爲我在本地運行Jboss。

所以,我應該怎麼寫的標籤內容,我試着用下面的

<VirtualHost *:80>   
    <Directory /var/www/example/> 
     Allow From All 
     RewriteEngine On 
     RewriteCond %{QUERY_STRING} (manage) 
     RewriteRule ^Mobile http://%{HTTP_HOST}/Mobile/web=%1 [NC,L] 
    </Directory> 
</VirtualHost> 

http://localhost:8081/Mobile/registerhttp://localhost:8081/Mobile/web/register 更換,請推薦

回答

0

看起來要重定向查詢只有當字符串包含一個單詞「manage」:

RewriteCond %{QUERY_STRING} (manage) 

如果要在查詢字符串不重定向包含某個單詞,你可以使用這樣的模式:

RewriteCond %{QUERY_STRING} (!manage) 

而重寫規則像這樣的:

RewriteRule ^Mobile /Mobile/web/register [NC,L,QSA] 

QSA可能會有所幫助在這裏:

追加任何查詢字符串從原始請求URL到在重寫目標中創建的任何查詢 字符串。

該解決方案將通過所有的查詢字符串參數和重定向從http://localhost:8081/Mobile/register?arg1=value1&arg2=value2http://localhost:8081/Mobile/web/register?arg1=value1&arg2=value2