I have this rewrite rule in web.config
in my C# / .NET project:
<rule name="URL Rewrite Test" stopProcessing="true">
<match url="(rewrite|testrewrite)-([0-9]+)/?" />
<action type="Rewrite" url="./aspx/rewritetest.aspx?rewrite={R:2}" appendQueryString="true" />
</rule>
This works well with the following URL:
http://localhost/rewrite-123/
The rule is rewriting the traffic to:
http://localhost/aspx/rewritetest.aspx?rewrite=123
Problem example: http://localhost/rewrite-123/mess/up/relative/path/
The URL rewrite still works well when the link includes additional path segments. The problem is it includes the path segments with forward slashes in the relative paths, making relative URLs not work.
Page content consists of hundreds of relative paths. How would be the best way to solve this combination of URL-rewrite and relative paths?
rewritetest.aspx.cs
:
public string relpath = "../pic/picture.gif";
Image1.ImageUrl = relpath;
rewritetest.aspx
:
<asp:Image ID="Image1" runat="server" />
Translates to ../../../../../pic/picture.gif
, and continues to function.
I believe it turn out like this:
http://localhost/rewrite-123/mess/up/relative/path/../../../../../pic/picture.gif
http://localhost/pic/picture.gif
<img src="../pic/picture.gif" />
<img src="<%=relpath %>" />
Path stays ../pic/picture.gif
and stops working.
I believe it turn out like this:
http://localhost/rewrite-123/mess/up/relative/path/../pic/picture.gif
http://localhost/rewrite-123/mess/up/relative/pic/picture.gif
src
attribute of the HTML elementimg
, which gets appears in the browser as-is. Instead of assuming what the URLs look like, use your browser's Developer Tools to inspect the actual HTML elements and their attributes. Use the Network tab to see what calls are made to the server...
everywhere