2017-04-24 73 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