RewriteRule ASP.NET Tutorial

The RewriteRule in htaccess looks like this in C#

RewriteRule ^match-site-url$  redirect-to-this

Example

RewriteRule ^hammadk.com/d*/d$ /test.php?id=$1&id2=$2

This will match the following patterns

hammadk.com/1234/5678
and the page will be send to test.php that is sitting in the root directory. 1234 is the first match located by d* and will be passed in the query string as test.php?id=1234.
1234 is followed by “/”. Since this is just static text (not a pattern) and thefefore will not be hold in any variable.
After this comes another integer, 5678. This will be catched by the second d*. Since this is the second regex expression, it will be held in variable$2. This string is passed to the query in this form
id2=5678

The complete redirect, takes this form

^hammadk.com/1234/5678$ #pattern
/test.php?id=1234$id=5678
Advertisements
This entry was posted in Tutorials/Tips. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s