Url Rewriting-Code for Rewriting

ASP.NET Basic URL Rewriting or code in master page

You could redirect your previous URLs to a new location just using your web.config file.

This is an example of redirecting a URL to another location in the Web.config file:

<system.webServer>
<rewrite>
<rule name="redirect to sign-in" stopProcessing="true">
<match url="previous-folder/SignIn.aspx"/>
<action type="Redirect" url="http://newWebSite.com/SignIn.aspx" redirectType="Permanent"/>
</rule>
</rewrite>
</system.webServer>

Is there something wrong with my rewrite code in .htaccess file

After a lot of painstaking experimentation the problem has at last been solved.

It seems that with the new iis8.5 server and Helion Ape I needed to put the rewrite rules into a web.config file instead of a .htaccess file.

The new rule for the example I gave in the question is:

<rule name="Imported Rule 6">
<match url="^uk-bed-breakfast-(.*)\.htm" ignoreCase="false" />
<action type="Rewrite" url="/bed-and-breakfast/region.asp?county={R:1}" appendQueryString="true" />
</rule>

Using this system the website is at last functioning correctly.

Many thanks to all who tried to help.

Tog

URL rewrite in ASP.net for multi language

Do you have access to a .htaccess file in your home directory? If so, you can make an automatic rewrite rule by writing the following

Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*)/contact-us/ /Pages/Contact.aspx?language=$1
RewriteRule /contact-us/ /Pages/Contact.aspx?language=en

Let me explain:

After RewriteRule, the user-friendly URL is on the left, here /(.*)/contact-us/ where (.*) is where jp will take place.
Then that jp is transposed on the real URL on the right, here /Pages/Contact.aspx?language=$1 to replace $1.

Input URL: http://www.example.com/jp/contact-us

Output URL: http://www.example.com/Pages/Contact.aspx?language=jp

For the second RewriteRule, as the URL http://www.example.com/contact-us/ does not match the first model, it will turn into http://www.example.com/Pages/Contact.aspx?language=en automatically.

Please remember that the .htaccess file MUST be in the root directory (alongside Pages folder). Otherwise you will not get the desired result.



Related Topics



Leave a reply



Submit