Forum Moderators: open

Message Too Old, No Replies

URL rewrite, no ISAPI. Absolute or relative paths?

         

aakk9999

11:18 pm on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



We are implementing database driven URL rewrite/redirect on .NET application hosted on IIS 6 server (there is no ISAPI module installed).

At the moment the internal URL paths within the scripts are referred to inconsistently, in a different ways, so firstly what we want to do is to comb through all scripts and make all internal URLs being referred to in an uniform way.

In this "tidy up", I am wondering what is the best to use, absolute paths (including domain name) or relative paths (but starting from root), e.g. should the internal URLs be:

href="http://www.example.com/widgets/widget.aspx"
img src = "www.example.com/images/widgets/blue-widget.jpg"

or

href="/widgets/widget.aspx"
img src = "/images/widgets/blue-widget.jpg"

Or does it not matter as long as we have full path starting from the root of the website consistently everywhere (i.e. no ../ ../../ ~ etc. in the path?

What are pros and cons of each?

I would like to add that once rewrite/redirect is implemented through db tables, it should also cater for domain wide page-to-page redirect from ccTLD to COM, done some months ago, as well as some other redirects done to fix URL capitalisation and few other mistakes. All of this is planned to be database driven rather than hardcoded as it is at the moment.

I have searched through previous posts but the information was from a few years back and also the opinions differed.

Ocean10000

1:10 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I prefer this method. I had to change hostnames a few too many times over the years for rather large projects where the hostnames were hard coded. Think of www.example.com changing to example.com and updating all the hardcoded links.

href="/widgets/widget.aspx"
img src = "/images/widgets/blue-widget.jpg"

marcel

5:46 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree, all of the websites I make link to other pages, images, resources etc in this manner

href="/widgets/widget.aspx"
img src = "/images/widgets/blue-widget.jpg"

Changing hostnames as Ocean mentioned is one reason, another is moving pages, making a copy of a page to another location, all of the links will still be OK.

aakk9999

1:12 pm on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you on replies, we have now asked for the change to be made to have full paths starting from domain root and with no domain name in internal links and images.

There is one case where I was told this cannot be done and the path is relative to the current folder. I was told that this cannot be done as this link is generated through .NET application. This place is the following line which is part of every .NET generated HTML:

<form name="Form1" method="post" action="widgets.aspx?id=7&lang=de" id="Form1">

I was told that the action= in the above line cannot be changed to start from root and that this is generated by .NET. I am not .NET programmer, could I have the advice if I should worry about this or not? I.e. will it break the links?

Below is the example of the folder structure we will be rewriting (environment: database driven redirect/rewrite, no ISAPI, IIS6, .NET 3.5).

If a request comes for:
www.example.com/resources/widgets.aspx?id=7&lang=de

This will be 301 redirected to:
www.example.com/de/green-widget

If a request comes for
www.example.com/de/green-widget

then this will be rewriten to
www.example.com/resources/widgets.aspx?id=7&lang=de
and passed on to application.

Question:
If in widgets.aspx the following line still has relative path as shown below, will it all still work?

<form name="Form1" method="post" action="widgets.aspx?id=7&lang=de" id="Form1">

Or is this going to be a problem and make the application break?

marcel

2:00 pm on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With Asp.Net 3.5 (SP1) you can set the value of the action attribute with the following:

Form1.Action = "My Friendly URL"

You'll have to test this with your custom rewrite rules though.

aakk9999

2:27 pm on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you on your reply.

My understanding from what the development is telling me is that they have no control over action= attribute and that this is set up automatically by the server. I am not sure if they are running SP1, I will ask.

If the action= is not set up to friendly URL, and it stays without the full path from the root, would the application break?

marcel

2:38 pm on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My understanding from what the development is telling me is that they have no control over action= attribute and that this is set up automatically by the server. I am not sure if they are running SP1, I will ask.

With ASP.Net 3.5 SP1 this will work, I just tested it again to make sure.

If the action= is not set up to friendly URL, and it stays without the full path from the root, would the application break?

As you have a custom rewrite mechanism this is something you will have to test yourself.