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

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

问题描述

我想知道当您无法访问 IIS 进行任何重写更改时,是否可以使用经典 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

...它将被重写为:

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

享受

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

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