重定向httpd文件

时间:2014-07-04 07:06:45

标签: regex apache

我尝试使用我发现的将https://pc.web.com/MyWeb/MyWebPortal.portal;jsessionid=jZLxT04pfQ(示例网站)重定向到http://pc.web.com的所有解决方案来编辑​​httpd文件。

但没有一个解决方案正在运作!任何人都可以指导我吗?

<VirtualHost *:80>

ServerName pcnow.web.com
DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"


RewriteCond %{pc.web.com} ^www\.(.*)$ [NC]

RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

甚至重定向也无效!!

1 个答案:

答案 0 :(得分:0)

您的配置中存在多个错误

<VirtualHost *:80>
ServerName pcnow.web.com
DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
RewriteCond %{pc.web.com} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
...

首先,您要将https请求重定向到http,这样您的虚拟主机可能应该侦听端口443,您应该在其中设置证书和相应的SSL配置。

其次,服务器名称ServerName pcnow.web.com中的拼写错误应为ServerName pc.web.com

第三,您的RewriteCond无效。 RewriteCond语法应采用以下形式: RewriteCond TestString CondPattern [flags]

因此,在您的情况下,TestString将类似于:%{REQUEST_URI}

CondPattern应该是匹配所有需要重定向的URI的正则表达式,例如:^/MyWeb/MyWebPortal\.portal;jsessionid=.*

或者一起: RewriteCond %{REQUEST_URI} ^/MyWeb/MyWebPortal\.portal;jsessionid=.*

最后,RewriteRule第二个参数收缩了无效的网址以进行重定向。原因是它将RewriteRule表达式匹配的值与不正确写入的RewriteCond条件匹配的值连接起来。

RewriteRule规则应如下:RewriteRule .* http://pc.web.com [R=301,L]

您可以在此处查看详细信息:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

相关问题