This forum has been moved here:
Helicon Tech Community Forum

ISAPI_Rewrite 3.0 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 3.0
Subject Topic: Newbie Question and Best Practice
Author
Message |
fvillena
Newbie


Joined: 25 April 2009
Posts: 9
Posted: 03 October 2011 at 3:04pm

I have a website that links to news articles using the URL mydomain.com/article.aspx?id=17544

I would like to change this to mydomain.com/17544/title-of-article

Can you provide the appropriate regular expression?

I presume if I wanted to have the URL without the number like mydomain.com/title-of-article I would need to use a map file and use code like the below?

Is it common to generate the contents of the map file dynamically from a database? I was just worried that if a CMS user creates an article which results in us having to re-build the map file at the same time someone is browsing the front-end of the website an error would occur. Is this fear founded?

RewriteEngine on
RewriteBase /
RewriteMap pagemap txt:pagemap.txt
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([^/]+) $1/${pagemap:$2|$2} [QSA]

----------------------------
pagemap.txt example:

Simple-Lifestyle renderscript1.aspx?release_id=12345
Scotts-Article renderscript2.aspx?release_id=12346&view=1
Scotts-Article-june renderscript2.aspx?event_id=34567

Thanks in advance.
Back to Top
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 04 October 2011 at 1:34am

I believe in your case it will be as simple as:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+)/[^/]+$ /article.aspx?id=$1 [NC,L]

If you leave the id in the URL, there's no need in using mapfile.

__________________
Regards,
Anton
Back to Top
 
fvillena
Newbie


Joined: 25 April 2009
Posts: 9
Posted: 27 November 2011 at 8:05pm

Hi Anton

I tried the above and while if I enter 15/niceurl as the test string in the Regex Test Tool I get /article.aspx?id=15 as expected in the result string on the actual website I get page not found.

Regards

Francisco
Back to Top
 
fvillena
Newbie


Joined: 25 April 2009
Posts: 9
Posted: 27 November 2011 at 8:54pm

I've just been doing some further testing and the above rule works for websites on my server IIS6 (Windows 2000) using ASP.NET 2.0 but not ASP.NET 4.0
Back to Top
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 29 November 2011 at 4:29am

This may happen because of Extensionless URLs feature that appeared in ASP.NET 4.0.
Please try to disable and check if it works.

__________________
Regards,
Anton
Back to Top
 
fvillena
Newbie


Joined: 25 April 2009
Posts: 9
Posted: 29 November 2011 at 5:43am

Thanks for that as I wouldn't have guessed that on my own :)

I'll try http://blogs.msdn.com/b/tmarq/archive/2010/06/18/how-to-disable-the-asp-net-v4-0-extensionless-url-feature-on-iis-6-0.aspx later and let you know how I get on.

Back to Top
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version