Forum Moderators: phranque

Message Too Old, No Replies

Is it possible to rewrite a rewrite?

rewite a rewrite, asp to php

         

emotn

2:06 pm on Jan 19, 2012 (gmt 0)

10+ Year Member



I have an asp site on a win server and am in the process of recoding the whole site to php. I have found some nifty code in these forums to rewrite the new php pages to the old asp page urls as it is an aged domain with heaps of links all over the net and I don't want to loose those links which I move to the linux server.

the asp pages are ugly urls

so i was wondering if it would be a good idea / or possible to then rewrite the rewritten asp pages to a nice url - and if this would affect my links in search engines etc? that is the main question!

current URL - default.asp?CatID=2&SubCatID=3

My idea
new page default.php?CatID=2&SubCatID=3 -> to go to default.asp?CatID=2&SubCatID=3

THEN default.asp?CatID=2&SubCatID=3 -> to go to /this-cat/this-sub-cat

Any advise and guidance will be most appreciated :D

lucy24

8:36 pm on Jan 19, 2012 (gmt 0)

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



Step One: Get a firm grip on the difference between rewrite and redirect. "Go to" may have meaning to you, but it has no meaning to mod_rewrite. (Do not ask a computer to read your mind. The consequences are seldom happy.)

Here, what you want is to

#1 REDIRECT

both

default.php?CatID=2&SubCatID=3
and
default.asp?CatID=2&SubCatID=3

to

http://www.example.com/2/3

when and only when they come in as THE_REQUEST

and then

#2 REWRITE

2/3/

as

default.php?CatID=2&SubCatID=3

There are, at a rough estimate, 47,000 threads over the last couple of years in this Forum giving code samples and discussing this particular rewrite-and-redirect two-step. At least half of them contain links to Apache's mod_rewrite page. So does the Forum Library (teeny little link somewhere near the top of this page, but only when you are not in Preview mode :().

It only needs to be done once. If at some future date you decide to change to jsp or some other language not yet invented, all you have to change is a couple of syllables in the Rewrite. Your new pretty URLs are for the ages.

g1smd

10:55 pm on Jan 19, 2012 (gmt 0)

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



To be clear, both pieces of code each use a RewriteRule. With slightly different coding each deliver a completely different result.

The redirect is activated when a user requests a parameter-based URL. The redirect tells the user to make a new request for a new URL, the 'friendly' URL. The redirect is a URL to URL translation.

The rewrite is activated when a user requests the friendly URL. The rewrite internally fetches the content from the parameter-based location in the server filesystem. The rewrite is a URL to filepath translation.

URLs and filepaths are not at all the same thing. URLs are used "out there" on the web (and contain a hostname). Filepaths are used "here" inside the server (where hostnames have no meaning - there are only folders and files).