I'm trying to redirect some unfriendly urls with more descriptive ones. These urls end in .aspx?cid=3916
with the last digits being different for each category name page. I want it to instead redirect to Category/CategoryName/3916
. I tried this in the web.config
file:
<location path="Category.aspx?cid=3916"> <system.webServer> <httpRedirect enabled="true" destination="http://www.site.com/Category/CategoryName/3916" httpResponseStatus="Permanent" /> </system.webServer>
but since it didn't end with just the extension, it didn't work. Is there an easy way to get this to work? I'm using IIS 7.5.
Redirects allow you to forward the visitors of a specific URL to another page of your website. In Site Tools, you can add redirects by going to Domain > Redirects. Choose the desired domain, fill in the URL you want to redirect to another and add the URL of the new page destination. When ready, click Create.
Use IIS rewrite rule to redirect (301) all www requests to non-www. Code first, talks later. Replace the “yourdomain” with your domain name and add it under the system. webServer section in the Web.
In IIS Manager, expand the local computer, right-click the Web site or directory you want to redirect, and click Properties. Click the Home Directory, Virtual Directory, or Directory tab. Under The content for this source should come from, click A redirection to a URL.
Then add code for the old location path and new destination as follows:
<configuration> <location path="services.htm"> <system.webServer> <httpRedirect enabled="true" destination="http://domain.com/services" httpResponseStatus="Permanent" /> </system.webServer> </location> <location path="products.htm"> <system.webServer> <httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" /> </system.webServer> </location> </configuration>
You may add as many location paths as necessary.
You probably want to look at something like URL Rewrite to rewrite URLs to more user friendly ones rather than using a simple httpRedirect
. You could then make a rule like this:
<system.webServer> <rewrite> <rules> <rule name="Rewrite to Category"> <match url="^Category/([_0-9a-z-]+)/([_0-9a-z-]+)" /> <action type="Rewrite" url="category.aspx?cid={R:2}" /> </rule> </rules> </rewrite> </system.webServer>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With