经典ASP URL重写 [英] Classic ASP URL Rewriting

查看:73
本文介绍了经典ASP URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当您无权访问IIS进行任何重写更改时,是否可以使用Classic ASP进行URL重写?

I was wondering if it is possible to do URL Rewriting with Classic ASP when you do not have access to IIS to make any rewrite changes?

我们有一家在线商店,通常将产品链接为/product.asp?ContentID=X,但希望提供一些对SEO更友好的内容,例如/product/unique-product-name

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

不幸的是,我们在一个共享的托管平台上,并且当前的托管服务提供商不愿意在他们的服务器上安装其他组件,以防它们导致其他问题. :(

Unfortunately we are on a shared hosting platform and are current hosting provider is not willing to install additional components to their server in case they cause issues for others. :(

推荐答案

稍后提供答案,但可以帮助您或其他人.

A later answer but could help you, or others.

我有时仍然使用经典的ASP编写代码,并且由于共享托管等原因,还不得不花一段时间来进行URL重写.

I sometimes still code in classic ASP, and also struggled with URL rewriting for a while because of shared hosting etc.

当我确实可以亲自访问或通过询问服务器支持团队访问IIS设置时,我使用了404错误方法.尽管此方法有效,但效果并不理想.它比正常"方式慢一点,并且像疯了一样阻塞了我的错误报告.

When I did have access to IIS settings, either by myself manually, or by asking the server support team, I used the 404 error method. Although this worked, it wasn't great. It was slightly slower than the "normal" way, and it clogged up my error reports like mad.

自从IIS7发布以来,我发现了一个托管提供程序,它提供了IIS7 URL重写模块(对我来说是GoDaddy)的使用,现在我要做的就是将一个web.config文件上传到我的根目录下应用程序,URL重写就可以完美地工作.

Since IIS7 came out, I found a hosting provider that offered the use of the IIS7 URL Rewrite Module (for me it was GoDaddy), and all I have to do now is upload a web.config file to the root of my application, and URL rewriting works perfectly.

因此,我的建议是,如果可以的话,将您的应用程序移至提供此服务的托管服务提供商.如果确实要更改主机,则只需要一个web.config文件(如下所示),然后将其上传到根目录即可.您完全不需要联系房东.

So my advice is, if you can, move your application to a hosting provider that offers this service. If and when you do change hosts, all you would need is a web.config file (below), upload it to the root and you're done. You won't need to contact the host at all.

将其另存为web.config:

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>

如果有人进入:

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

享受

这篇关于经典ASP URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆