简体   繁体   English

如何将带有.aspx的URL正确重写为不带有.aspx的URL?

[英]How can I correctly rewrite a URL with .aspx to a URL without .aspx?

I have a site that currently uses the .aspx extension on its pages. 我有一个网站,当前在其页面上使用.aspx扩展名。 It's getting a Joomla conversion and the .aspx extension will not work anymore. 它正在进行Joomla转换,.aspx扩展名将不再起作用。 I need it so that if someone enters the .aspx extension, it will just get removed the URL so none of the SEO on the current site breaks. 我需要它,以便如果有人输入.aspx扩展名,它只会被删除URL,因此当前站点上的SEO都不会中断。

For example, I need www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx to be rewritten/redirected to www.arrc.com.php5-17.websitetestlink.com/services/managed-services 例如,我需要将www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx重写/重定向到www.arrc.com.php5-17.websitetestlink.com/services/managed-服务

This is what I have in my web.config: 这就是我的web.config中的内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
     <rules>
      <rule name="Migrate to PHP">
       <match url="^([_0-9a-z-]+)\.aspx" />
       <action type="Redirect" redirectType="Permanent" url="{R:1}" />
      </rule>
      <rule name="Rewrite .aspx">
         <match url="^([_0-9a-z-]+)/?([_0-9a-z-]+)\.aspx" />
         <action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}" />
      </rule>
     </rules>
    </rewrite>
  </system.webServer>
</configuration>

The first URL match is for any URLs that have a URL like services.aspx instead of services/managed-services.aspx 第一个URL匹配是针对具有URL的任何URL,例如services.aspx而不是services / managed-services.aspx

Whenever I go to www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx it gives me an internal server error, but www.arrc.com.php5-17.websitetestlink.com/services.aspx rewrites correctly. 每当我访问www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx时,都会给我内部服务器错误,但是www.arrc.com.php5-17.websitetestlink.com/services。 aspx正确重写。 What can I do to fix this? 我该怎么做才能解决此问题?

They are greedy, switch the order. 他们很贪心,切换顺序。

   <rule name="Rewrite .aspx">
     <match url="^([_0-9a-z-]+)/?([_0-9a-z-]+)\.aspx" />
     <action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}" />
  </rule>

 <rule name="Migrate to PHP">
   <match url="^([_0-9a-z-]+)\.aspx" />
   <action type="Redirect" redirectType="Permanent" url="{R:1}" />
  </rule>

Two potential issues: 两个潜在的问题:

  1. I think for rewriting, it's going to hit them in order, which means the first rule is going to always kick off. 我认为对于重写而言,它将按顺序击中它们,这意味着第一个规则将始终启动。 Try switching the order of the rule. 尝试切换规则的顺序。

  2. The dash should work correctly in [_0-9a-z-], but try escaping the dash. 破折号在[_0-9a-z-]中应该可以正常使用,但是请尝试转义破折号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM