Forum Moderators: phranque

Message Too Old, No Replies

Moving from ASP site to Apache

how best to redirect .asp?var=x to new clean urls

         

SuzyUK

11:24 am on Feb 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I asked this before but wasn't able to tell you the new URL format so here goes..

URLs, at present. are:

directory/detail.asp?var=[i]n[/i]
where n is a number

new home will be:

newdirectory/product_title

the product title will be different for each old "var"

This section is small (about 10 pages) and is guaranteed to follow the rule: n = some_title

but there is also an larger section e.g.

archives/article.asp?var="x"

and these are more likely to go to: category/title
where the category will also change (i.e. there will no longer be an archives directory)
e.g.
var="1" might map to red/some_title
var="2" might map to blue/another_title

will I have to write separate rules into the htaccess for each and every page (can you even use htaccess to rewrite based on variables?)

or could I perhaps set up a couple of files to have the same directory structure as is present on old site then have the .asp extension parse PHP and write a script to redirect based on the variable?

topr8

12:07 pm on Feb 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>>This section is small (about 10 pages) and is guaranteed to follow the rule: n = some_title

sadly in this case each rule will have to be written by hand, becasue:

condsider this - effectively you are convertion a number var=1,2,3 etc to a name
there is no way to know what the name would be, so you have to write each instance out.

in order to have written a rule you would have have to do something like this

directory/detail.asp?var=n where n is a number
new home will be: newdirectory/n where n is the same number
.[this would also only work if directory always became the same new directory

... you are in a similiar situation with the second bunch of redirects.

i think your only alternative would be to set up the pages
directory/detail.asp
and
archives/article.asp

set apache to parse .asp pages with the php parser, [or do this in htaccess] then on those pages, get the querystring values make a database call or whatever to calculate what the correct directory and page names would be - assuming they are already in a database, and write a 301 redirect on the page.

sorry its early sunday morning and i haven't been that clear but hopefully you get my gist.

jdMorgan

4:30 pm on Feb 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another point to consider is that there are three steps to the process:

First, you have to change your pages to use/show/link to clean URLs, and then you have to 'connect' those clean URLs back to whatever script is being used to produce them. This is typically done using an internal rewrite, since using an external redirect would result in the old query-based URLs being retained by the search engines.

Only after these first two steps are done might a redirect come into to play: You might wish to redirect the old query-based URLs to the new clean URLs to speed their replacement in the search results. However, this step is not strictly necessary, except for that reason and as a usability factor (users may have bookmarked the old URLs, and this step prevents those bookmarks from being orphaned.)

Jim

SuzyUK

6:04 pm on Feb 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks topr8
set apache to parse .asp pages with the php parser, [or do this in htaccess] then on those pages, get the querystring values make a database call or whatever to calculate what the correct directory and page names would be - assuming they are already in a database, and write a 301 redirect on the page.

I think that's what I would prefer to do, my head can cope with that logic - though I won't be able to make a database call. The site is moving to a CMS (Drupal) and while I might be able to write a custom mod, I like the idea of separate files better.. So as there's no database calls would I just do this as an if/else style - listing the variables and redirecting to new URL? or would that be a long-winded way to do it...

jd, I *think* I'm covering your steps (by accident?) - I'm inputting the existing articles into new database via the CMS (on production subdomain) it's the CMS which is renaming them cleanly, is this what you mean about an internal script taking care of rewrites? - and the final step is what I'm asking about (I think) and is because yes I do not want to lose the search results and help the inbound links/bookmarks, and then I'm thinking I can take care of getting some of the major inbounds changed once everything else is working

topr8

6:57 pm on Feb 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> So as there's no database calls would I just do this as an if/else style - listing the variables and redirecting to new URL? or would that be a long-winded way to do it...

yes you are right on both counts :)

it would be long winded but that is the way you would have to do it
(or of course just manually writing each one in the .htaccess instead)

[ps. use the php switch function which is similiar to the asp SELECT CASE function ... it'll be much easier than a series of else statements]

i did something similiar with around 500 pages once when i slipped the site over to apache and changed the uri structure for the site.