PDA

View Full Version : SE Friendly Urls (URL rewriting)


boomers
06-06-2007, 09:40 AM
Has any here who has a .NET site hosted on CSNM got SE Friendly URL's inplace?

For example. If you goto www.pillage.com (http://www.pillage.com) and type in a search then the page youre results are shown on will be www.pillage.com/search/(searchterm).html (http://www.pillage.com/search/(searchterm).html)

As oppossed to www.pillage.com/search/results.aspx?searchterm=(searchterm (http://www.pillage.com/search/results.aspx?searchterm=(searchterm))

- Ive read a few way on achieving this and was wondering what others have found as the best way to implement it.

siphilp
06-06-2007, 09:49 AM
I would look at httphandlers and url rewriters for .net

httphandlers http://msdn2.microsoft.com/en-us/library/f3ff8w4a(VS.71).aspx (use this on my website for now)

rewriter http://msdn2.microsoft.com/en-us/library/ms972974.aspx

there are other ways i.e. using an ISAPI Re-write component (this i believe costs £15 setup fee per domain due to CPU power it uses.)

wallacr
10-06-2007, 09:47 PM
I use url rewriting on my site. What language are you using? VB or C#? If it's VB, I can give you the code if that helps. It's actually fairly straight forward.

Cheers,

Rich

boomers
10-06-2007, 10:30 PM
Hey

- I am indeed coding in VB, if there is some generic code then yeah i'd love it if you can let me see :)

wallacr
10-06-2007, 10:51 PM
Hey

- I am indeed coding in VB, if there is some generic code then yeah i'd love it if you can let me see :)

Ok, here you go then, I've posted some sample code for you at the below url:

http://www.csnmforums.com/showthread.php?t=1214

Hope it helps.

Cheers,

Rich

boomers
11-06-2007, 12:14 PM
Thanks for the example, this looks great and I plan on adding it to at least 1 of my more static websites... but I do have 1 question.

My site (http://www.lookthisup.com) is run i'd say 99% from various databases... so Ive only got say 15 pages in my VisualStudio project but when Google crawls my site its going through thousands of pages.

A good example is the cheats section (http://www.lookthisup.com/game-cheats.aspx), when you click on one of the link it adds the querystring for the 'platform' eg: http://www.lookthisup.com/game-cheats.aspx?p=Xbox the 'Xbox' querystring is obviously dictating the platform. And then you get on screen links to the various Xbox games, once you click on one of them you get http://www.lookthisup.com/game-cheats.aspx?g=Alias&p=Xbox so 'g' refers to the game and 'p' to the platform.

Using this system of URL rewriting, does it mean I would have to put in a
different 'mapped url' within the web.config file for each of the cheats that I have inthe database?

- If im reading it right it means I *would* have to, but due to the amount of the site thats running from a DB it means it wouldnt be feasible :(

Though with the site I mentioned in my first post, (pillage.com) that seems to use a dynamic way of rewriting the URL, as no matter what you search for you will always end up at www.pillage.com/search/(searchterm).html (http://www.pillage.com/search/(searchterm).html)

- So the admin would never have been able to add every potential search term to the .config file.

wallacr
11-06-2007, 11:01 PM
You could do it with one url and one page, like below:

Say you want your url to be redirect to the the below:


page.aspx?g=Alias&p=Xbox


And you'd like to use a url like:


resultsgamealiasplatformxbox.aspx


Notice I put the querystring in red to stand out more? Well now you just set the RegExUrlMapping to recognise anything after game and before platform as one querystring and anything after platform as another querystring.

An example of this would be:


<addurl="~/resultsgame(.*)platform(.*)\.aspx"mappedUrl="~/page.aspx?g=$1&amp;p=$2"/>


Hope that makes sense and helps.

Cheers,

Rich

boomers
12-06-2007, 09:10 AM
Sir you are great - thats seems to be exactly what im after!

Im about to take the kids out for the day but I'll be trying this as soon as possible. - I'll let you know how it goes when Ive given it a go.

I really appreciate the time you've taken to help me with this. :)

wallacr
12-06-2007, 09:19 AM
Sir you are great - thats seems to be exactly what im after!

Im about to take the kids out for the day but I'll be trying this as soon as possible. - I'll let you know how it goes when Ive given it a go.

I really appreciate the time you've taken to help me with this. :)

Good luck with getting it all sorted and give me a shout if you need anything.

Thinking about it, you may need to swap the position of the $1 & $2 variables, but see how you get on.

Cheers,

Rich

boomers
13-06-2007, 11:00 PM
Ive given it a go but there is a problem, when I use this in my project the .css doesnt load when the page is loaded.

Will look into it some more :)

Update
- Well it seems to be because im using masterpages, trying to find a solution now.

screwsoft
14-06-2007, 01:10 AM
Had a similar problem with master pages once, trying creating a theme (it can be blank) then if you put the css file in there, .net seems to find it again.

boomers
16-06-2007, 10:03 PM
Something very strange has happened... this is/was working fine. So I started a new project and followed these same instructions *but* - with the final step of setting the actual paths of the 'virtual url' and actual url I hit a problem.

Within the web.config file the following part is highlighted in the Warning list (not error list so i can still compile it all)


<RegExUrlMappingenabled="true">
<addurl="~/(.*)/default\.aspx"mappedUrl="~/Default.aspx?id=$1"/>
</RegExUrlMapping>


(thats the 'regexurlmapping' part...) - the warning is


Warning 1 The element 'system.web' has invalid child element 'RegExUrlMapping'. List of possible elements expected: 'anonymousIdentification, authentication, authorization, browserCaps, clientTarget, compilation, customErrors, deployment, deviceFilters, globalization, healthMonitoring, hostingEnvironment, httpCookies, httpHandlers, httpModules, httpRuntime, identity, machineKey, membership, mobileControls, pages, processModel, profile, roleManager, securityPolicy, sessionPageState, sessionState, siteMap, trace, trust, urlMappings, webControls, webParts, webServices, xhtmlConformance, caching'.


Which from what I can see is basically saying it does not recognise 'RegExUrlMapping'

- Just wondering if anyone else has had this problem also?