代码之家  ›  专栏  ›  技术社区  ›  buggy1985

mod ou rewrite rewriterule不工作

  •  0
  • buggy1985  · 技术社区  · 14 年前

    这是这个问题的后续行动: 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页找不到错误。

    由于以下简单规则工作正常,因此启用了mod_rewrite:

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

    你能帮忙吗?

    谢谢

    2 回复  |  直到 14 年前
        1
  •  0
  •   Don    14 年前

    也许试试这个

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

    它认为这是不正确的。不能将URL用作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
    

    是(编辑:出于某种原因,您希望匹配最后一部分路径,我将不胜感激)

    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]
    

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