繁体   English   中英

IIS URL重写问题与web.config

[英]IIS URL rewrite issue with web.config

我使用mod_rewrite重写了.htaccess,并使用在线转换器将其转换为IIS的web.config。

这是我的web.config中的一行:

 <rule name="rule 1G">
    <match url="cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=viewCat&catId=$1&%1"  ignoreCase="true" />
    <action type="Rewrite" url="/"  />
 </rule>

有了这个我得到错误:

Configuration file is not well-formed XML

该错误在上面的第二行中触发。

有人知道我在做什么错吗?

以下是原始htaccess文件的一部分:

AddType x-mapp-php5 .php

## Activate the mod_rewrite Engine

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$    index.php?_a=viewCat&catId=$1&%1 [NC]

您需要使用&amp;转义属性值中的“ &amp;

<rule name="rule 1G">
  <match url="cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=viewCat&amp;catId=$1&amp;%1"  ignoreCase="true" />
  <action type="Rewrite" url="/"  />
</rule>

注意 您可能会发现http://xmlvalidation.com/对于调试XML文件很有帮助。

更新

上面的更改只会修复XML有效性错误,而不能解决重写规则本身。 match元素仅应描述匹配条件(即Apache RewriteRule的第一部分),而目标URL应在action元素中描述。

反向引用也具有不同的语法。

我建议尝试以下规则定义(不幸的是,我无法检查自己是否缺少IIS):

<rule name="rule 1G">
  <match url="cat_([0-9]+)(\.[a-z]{3,4})?(.*)$" ignoreCase="true" />
  <action type="Rewrite" url="index.php?_a=viewCat&amp;catId={R:1}&amp;" appendQueryString="true" />
</rule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM