mod_rewrite RewriteRule is not working

人盡茶涼 提交于 2020-01-25 09:05:30

问题


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

I got this Rewrite Rule:

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

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 is enabled, as the following simple rule is working fine:

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

Can you help?

Thanks


回答1:


maybe try this

RewriteRule ^/(.+)/page/([^/]+)/(.*)$ domain/index.php?page=$2&host=%{HTTP_HOST} [QSA,NC,L]



回答2:


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

What you should write instead of

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.



来源:https://stackoverflow.com/questions/2880996/mod-rewrite-rewriterule-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!