friendly URL

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 41
Joined: 25 May 2012, 17:31

friendly URL

25 May 2012, 17:41

Hi,

What would be the code to have this link:

http://www.mysite.com/Webpage.aspx?Webp ... Id=15.aspx

Look like this:

http://www.mysite.com/Nutrition-Info

THanks,

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: friendly URL

28 May 2012, 09:38

Do you want it to be a single-url rule? Or do you want to create a universal rule for a large group, using mapfiles?

Regards
Andrew

User avatar
Posts: 41
Joined: 25 May 2012, 17:31

Re: friendly URL

29 May 2012, 11:12

Hi Andrew,

I am probably going to use a map file and if you could just give me a hand with this one and how the format should be, I could probably just add to the map file for the rest. Thanks for your help I appreciate it!

John

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: friendly URL

30 May 2012, 10:19

Hello,

Try using the following:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteMap mapfile txt:mapfile.txt

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond ${mapfile:%1|NOT_FOUND} !NOT_FOUND
Rewriterule ^Webpage\.aspx$ /${mapfile:%1} [NC,R=301,L]


file mapfiel.txt must be located in the same folder with .htaccess(or httpd.conf - the same place where the rules are located).
Content of the mapfile is:

WebpageId=106&CategoryId=15.aspx Nutrition-Info
WebpageId=106&CategoryId=145 OtherPage
WebpageId=1342&CategoryId=187 AntherPage


You may find out more about mapfiles here

regards
Andrew

User avatar
Posts: 41
Joined: 25 May 2012, 17:31

Re: friendly URL

30 May 2012, 15:12

This is really close, but it's coming back now as
http://www.mysite.com/Nutrition-Info?We ... Id=15.aspx
and I need it to be just
http://www.mysite.com/Nutrition-Info

Any ideas?

Thanks,

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: friendly URL

31 May 2012, 05:13

Sorry, alway forget about that. Please, replace

Code: Select all
Rewriterule ^Webpage\.aspx$ /${mapfile:%1} [NC,R=301,L]

with
Code: Select all
Rewriterule ^Webpage\.aspx$ /${mapfile:%1}? [NC,R=301,L]



Regards
Andrew

User avatar
Posts: 41
Joined: 25 May 2012, 17:31

Re: friendly URL

31 May 2012, 17:43

Ok getting closer, this does rewrite it so that it is pretty http://www.mysite.com/Nutrition-info but I get a 404 because the page does not exist. Do I need a reverse mapfile as well to correspond to the existing page?

Thanks,

John

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: friendly URL

01 Jun 2012, 05:34

That's correct now you need reversemapfile and the rule that would rewrite back.

Code: Select all
RewriteMap revmapfile txt:revmapfile.txt

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ${revmapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) /Webpage.aspx?${revmapfile:$1} [NC,L]


Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 16 guests