如何实现旧URL到新URL的301永久重定向?附内页示例
Since you're updating your inner pages from .aspx extensions to clean URLs, here are the 301 redirect implementations for the most common server setups:
Apache (using .htaccess)
If your site runs on Apache, add these rules to your root .htaccess file.
Specific Redirects for Your Pages
This targets exactly the URLs you listed—ideal if you only have a handful of pages to update:
# Redirect about-us.aspx to about-us Redirect 301 /about-us.aspx /about-us # Redirect portfolio.aspx to portfolio Redirect 301 /portfolio.aspx /portfolio # Redirect contact-us.aspx to contact-us Redirect 301 /contact-us.aspx /contact-us
General Rule (for more .aspx pages)
If you have other inner pages following the same pattern (e.g., services.aspx → services), use this rewrite rule to handle all at once:
RewriteEngine On RewriteRule ^(.*)\.aspx$ /$1 [R=301,L]
This strips the .aspx extension from any matching request and redirects to the clean URL.
Nginx
For Nginx servers, edit your site's server configuration file (typically in /etc/nginx/sites-available/) and add these rules inside the server block:
Specific Redirects
# Redirect about-us.aspx to about-us rewrite ^/about-us.aspx$ /about-us permanent; # Redirect portfolio.aspx to portfolio rewrite ^/portfolio.aspx$ /portfolio permanent; # Redirect contact-us.aspx to contact-us rewrite ^/contact-us.aspx$ /contact-us permanent;
General Rule
To handle all .aspx pages:
rewrite ^/(.*)\.aspx$ /$1 permanent;
After making changes, reload Nginx with sudo systemctl reload nginx to apply them.
IIS (using web.config)
If your site is hosted on IIS, add these rules to your root web.config file:
<configuration> <system.webServer> <rewrite> <rules> <!-- Specific redirect for about-us.aspx --> <rule name="Redirect about-us.aspx" stopProcessing="true"> <match url="^about-us.aspx$" /> <action type="Redirect" url="/about-us" redirectType="Permanent" /> </rule> <!-- Specific redirect for portfolio.aspx --> <rule name="Redirect portfolio.aspx" stopProcessing="true"> <match url="^portfolio.aspx$" /> <action type="Redirect" url="/portfolio" redirectType="Permanent" /> </rule> <!-- Specific redirect for contact-us.aspx --> <rule name="Redirect contact-us.aspx" stopProcessing="true"> <match url="^contact-us.aspx$" /> <action type="Redirect" url="/contact-us" redirectType="Permanent" /> </rule> <!-- Optional general rule for all .aspx pages --> <rule name="Remove .aspx extension" stopProcessing="true"> <match url="^(.*)\.aspx$" /> <action type="Redirect" url="/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Quick Tips
- Test redirects after setup: Use
curl -I http://www.emulateinfotech.com/about-us.aspxto check for a301 Moved Permanentlystatus and correct target URL. - 301 redirects are permanent—search engines will update their indexes to point to new URLs over time.
- Ensure your clean new URLs work properly before enabling redirects to avoid broken links.
内容的提问来源于stack exchange,提问作者George Bailey

