2012-01-23 162 views
0

我想做转发所有传入的请求到https,除非URL包含/ axis2(http:// locatlhost/axis2)在URL中。这就是我写(在我httpd.conf file):问题与Apache mod_rewrite

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/axis2$ [NC] 
RewriteRule $ https://%{HTTP_HOST}%{REQUEST_URI} [L,R] 

这不是工作,我无法调试原因。谁能帮我。

+0

你试过从'^/axis2 $'中删除开始的斜杠'/',所以看起来像'^ axis2 $' –

回答

1

你为端口443单独设置了VirtualHost吗?

如果是尝试在ssl.conf/VirtualHost指令由ssl设置除去从VirtualHost指令的__default__

应该看看哪些是这样的:

所有我会建议你在你的 VirtualHost添加此的
<VirtualHost _default_:443> 

第一。记录活动或mod_rewrite。这对于调试更有帮助,并且更高的RewriteLogLevel更适合调试。

RewriteEngine On 
RewriteLog "/path/to/your/rewrite.log" 
RewriteLogLevel 3 

RewriteLogLevel Docs

要禁用改写简单的设置级别为0。这样的行为的日志记录禁用所有重写操作日志。 使用较高的Level值会显着降低Apache服务器的速度!仅在调试时使用大于2的级别的重写日志文件!


试试这个您的问题:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/?axis2/(?:.*)$ [NC] 
RewriteRule ^(.*)(/?axis2/)(.*)$ https://$1$2$3 [L,R=301] 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}%{QUERY_STRING} [L,QSA,R=301] 

如果%{REQUEST_URI}没有启动,并与/axis2axis2//axis2/axis2结束它会将您的URI重定向到https并停止任何进一步的规则重写。

否则,仅此将执行:

RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}%{QUERY_STRING} [L,R=301] 

R = 301意味着一个永久重定向。如果仅指定了R,则将完成临时重定向,即302。

+0

感谢您的回应!但是,这不起作用,并且要排除的URL将具有种类http:// localhost:// axis2/connector。即使我试图打一个类型为http:// localhost/axis2 /的URL,它也会陷入无限循环。什么可能是这个问题? – Ankit

+0

无限循环是什么意思?该页面无法加载? – ThinkingMonkey

+0

是的,日志是这样的:初始化重写引擎与请求的uri/axis2/ 应用模式'^(。*)$'到uri'/ axis2 /' RewriteCond:input ='/ axis2 /'pattern ='!^ /?axis2 /?$'[NC] =>不匹配 应用模式'^(。*)$'to uri'/ axis2 /' rewrite'/ axis2 /' - >'http:// localhost/axis2 /' 明确强制重定向http:// localhost/axis2/ 转义http:// localhost/axis2 /用于重定向 重定向到http:// localhost/axis2/[REDIRECT/301] init请求uri/axis2/ 的重写引擎将模式'^(。*)$'应用于uri/axis2 /' RewriteCond:input ='/ axis2 /'pattern ='!^ /?axis2 /?$'[NC] =>不是m – Ankit