mod_rewrite RewriteRule不起作用 [英] mod_rewrite RewriteRule is not working

查看:200
本文介绍了mod_rewrite RewriteRule不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是此问题的后续内容:重写URL-如何获取主机名和路径?

This is a follow-up of this question: Rewrite URL - how to get the hostname and the path?

我有这个重写规则:

RewriteEngine On
RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl

这似乎是正确的,而且正是我所需要的.但这在我的服务器上不起作用.我收到404页面未找到错误.

it seems to be correct, and exactly what I need. But it doesn't work on my server. I get a 404 page not found error.

mod_rewrite已启用,因为以下简单规则可以正常工作:

mod_rewrite is enabled, as the following simple rule is working fine:

 RewriteEngine On
 RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

可以帮忙吗?

谢谢

推荐答案

它认为这是不正确的.您不能使用url作为RewriteRule的第一个操作数.

It believe it's not correct. You cannot use a url as the first operand of RewriteRule.

您应该写些什么而不是

RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl

是(出于某种原因,您想匹配最后一部分路径,我将负责)

is (edit: for some reason you want to match the last portion path, I'll oblige)

RewriteCond %{HTTP_HOST} !=""
RewriteRule ^/(.*?)([^/]+)(?:/)?$ http://www.xmldomain.com/bla/page?rtype=xslt&xsl=http%3A%2F%2F%{HTTP_HOST}%2F$1$2.xsl%2A [QSA,B,P,NE]

还请注意,虚拟主机不会自动继承重写规则.您必须显式激活继承.

Also note that rewrite rules are not automatically inherited by virtual hosts. You must activate inheritance explicitly.

这篇关于mod_rewrite RewriteRule不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆