Classic ASP URL Forwarding

I was wondering if it is possible to rewrite URLs with classic ASP when you don't have access to IIS to make any rewrite changes?

We have an online store where products are usually linked like /product.asp?ContentID=X but would like to have something more SEO friendly like / product / unique -product-name

Unfortunately we are on a shared hosting platform and the current hosting provider is unwilling to install additional components on their server if they cause problems for others. :(

+2


source to share


3 answers


Later answer, but may help you or others.

I sometimes still code for classic ASP and also tried to rewrite URLs for a long time due to shared hosting etc.

When I had access to the IIS settings, either on my own or by asking the server support team, I used the 404 error method. While it worked, it wasn't very good. This was a little slower than the "normal" way and littered my error messages like crazy.

After IIS7 came out, I found a hosting provider that suggested using the IIS7 url rewriter module (for me it was GoDaddy) and now I need to load the web.config file to the root of my application and the url rewriting works fine.

So my advice is, if you can, move your application to a hosting provider that offers this service. If and when you change hosts, all you need is a web.config file (below), upload it to your root directory and you're good to go. You don't need to mess with the host at all.

Save this as web.config:



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite to friendly URL">
                      <match url="^blog/([0-9]+)/([_0-9a-z-]+)" />
                      <action type="Rewrite" url="blog/article.asp?id={R:1}&amp;title={R:2}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

      

If anyone enters:

http://mydomain.com/blog/1/the-article-title

... it will be rewritten to:

http://mydomain.com/blog/article.asp?id=1&title=the-article-title

Enjoy

+4


source


Probably no.



You should at least change your IIS configuration to 404 pages for the code to take control.

+2


source


I did it. It's kludgy but workable.

As another commenter pointed out, you can create a custom 404 page. You will need at least a little cooperation with your hosting provider to change IIS to send 404 errors to a custom page in your directory. They shouldn't have a problem with it; will not affect other users.

As far as I can tell, in your custom 404 ASP page everything you actually have access to is the original url via Request.ServerVariables ("QUERY_STRING")

Then you can parse the contents of this and redirect to whatever is needed with Server.Transfer (not Response.Redirect because you want to redirect to server side, not client side redirect)

Make sure you have a crash case, albeit to handle actual 404 errors!

+2


source







All Articles