【问题标题】:mod_rewrite RewriteRule is not workingmod_rewrite RewriteRule 不工作
【发布时间】:2010-05-21 09:40:53
【问题描述】:

这是这个问题的后续: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]

你能帮忙吗?

谢谢

【问题讨论】:

  • ServerFault 问题,可能。

标签: mod-rewrite


【解决方案1】:

不妨试试这个

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 好的。但这并不能帮助我解决我的问题。我需要在最后一个斜杠(“页面”)之后单独捕获字符串。替换部分应如下所示: http://www.xmldomain.com/bla/$2?rtype=xslt&xsl=http%3A%2F%2F%{HTTP_HOST}%2F$1$2.xsl Pattern 部分看起来如何这样做?
    • 那是我的错,我提供了正则表达式。正则表达式是否对变量进行操作?
    • @buggy1985 好的,那么 1 美元是多少?
    • @Artefacto 路径。看这里:stackoverflow.com/questions/2875405/…
    • @buggy1985 我不明白。 $1 匹配 /path/to/,$2 匹配页面并重写为 $1$2 与 $1 匹配 /path/to/page 并重写为 $1 相同。但无论如何我都会编辑答案
    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 2012-10-10
    • 2015-04-28
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 2011-01-07
    相关资源
    最近更新 更多