在 Azure 上托管的 webapp 中重写 web.config 中的规则
Rewrite Rule in web.config in webapp hosted on Azure
我正在尝试重定向请求 https://www.mywebsite.com/product/Apple/Green (not a real link) to https://www.mywebsite.com/product.php?prod=Apple&type=green(不是真实的 link)
我在 web.config 文件中添加了以下规则,但它似乎不起作用
<rule name="rwrite">
<match url="^product/([A-Za-z0-9]+)/([A-Za-z0-9-]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url=“product.php?prod={R:1}&type={R:2}" appendQueryString="true" /></rule>
我在 URL Writer 中测试了这段代码,它给了我正确的输出。但是,如果我上传此配置文件,它会加载 product.php 文件,但无法加载 html 部分中包含的其他 JS 文件和 css 文件。
这不是 URL 重写问题。我的猜测是您正在使用相对路径加载 HTML 部分中的 JS 文件和 CSS 文件。也许看起来像这样:
<head>
<script src="index.js"></script>
</head>
这与浏览器地址栏中的URL有关。为防止这种情况发生,您需要在文件路径的开头添加 /
(相对于域的根文件夹):
<script src="/index.js"></script>
或对这些静态文件使用完整路径:
<script src="http://mywebsite.com/index.js"></script>
我正在尝试重定向请求 https://www.mywebsite.com/product/Apple/Green (not a real link) to https://www.mywebsite.com/product.php?prod=Apple&type=green(不是真实的 link)
我在 web.config 文件中添加了以下规则,但它似乎不起作用
<rule name="rwrite">
<match url="^product/([A-Za-z0-9]+)/([A-Za-z0-9-]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url=“product.php?prod={R:1}&type={R:2}" appendQueryString="true" /></rule>
我在 URL Writer 中测试了这段代码,它给了我正确的输出。但是,如果我上传此配置文件,它会加载 product.php 文件,但无法加载 html 部分中包含的其他 JS 文件和 css 文件。
这不是 URL 重写问题。我的猜测是您正在使用相对路径加载 HTML 部分中的 JS 文件和 CSS 文件。也许看起来像这样:
<head>
<script src="index.js"></script>
</head>
这与浏览器地址栏中的URL有关。为防止这种情况发生,您需要在文件路径的开头添加 /
(相对于域的根文件夹):
<script src="/index.js"></script>
或对这些静态文件使用完整路径:
<script src="http://mywebsite.com/index.js"></script>