Forum Moderators: phranque
I am changing a site in it entirety and want to specifically target old pages with a 301 redirect.
So
[exampleE.COM...]
would redirect to something like
http://www.example.COM/accom_detail-PropertyID-64.htm
64 being the identifyer
I have 85 individual URLs to redirect. I am happy to write them all in if i have to.
The main thing is that the starting URL does not exist nor does the folders. The original URL has been rewritten on IIS and the new one will be in Apache.
Any help is really appreciated as google links directly to those pages.
Ben
[edited by: jdMorgan at 1:52 pm (utc) on June 22, 2009]
[edit reason] example.com [/edit]
would redirect to something likehttp://www.example.COM/accom_detail-PropertyID-64.htm
"Something like" isn't precise enough. We need to know *exactly* what the relationship(s) between the original/old URLs and the new URLs need to be, because mod_rewrite will also need to "know" this exact relationship.
When using mod_rewrite in this application, you can do two things -- either or both, that is: You can copy parts of the original/old URL into the new URL -- as you would evidently want to do here with "64"-- and/or you can replace all or parts of the URL with fixed text strings.
So, for example, we need to know how, looking at the originally-requested old URL, you intend to determine that the new URL should contain "/accom_detail-PropertyID-". If *all* requested old URLs are *not* to be redirected to "/accom_detail-PropertyID-<nn>", then you must describe the method that can be used to determine which originally-requested/old URLs should and should not be redirected to this new path -- how that path is to be determined (solely) from the information carried by the original (old URL) request.
In addition, if there are other old URLs that need to be redirected differently (i.e. *not* redirected to new URLs like "/accom_detail-PropertyID-<nn>", but rather to some other new URL-path, then we need to know all about those as well.
If there is no clear old/new URL-mapping relationship, then there are a several choices, limited by what privileges you have on the server: You can implement one rule for each old-URL->new-URL translation, you can internally rewrite to a script to generate the new URL redirect based on a (new or existing) database lookup, or you can use a RewriteMap, either to call a lookup-and-redirect script, or to access a fixed (e.g. text-based) "translation table." This latter option requires server configuration privileges to *define* the RewriteMap, but no server privileges are needed to *use* the map after it has been defined.
As you will see, it is not the coding that is the major challenge here; It is precisely defining the problem so that it can be correctly-coded that is the most difficult part of the job.
Having said that, we ask that you make an effort at coding a solution, in order to establish a baseline for discussion here. The resources cited in our Apache Forum Charter [webmasterworld.com] may prove useful in this regard.
Jim
Thanks for the informative reply. I am having difficulty understanding this particular issue as it seems to me the original rewrite in asp is a little SHI%^Y... The only differentiating item is the number (in the example above it is 64). I have tried the rewrite, but because the folders and files dont exist for the asp file, all I could get going was a generic rewrite of any file or folder that DOES NOT exist to a new link. I didnt post the script as I think it would cloud the question. Here is a quick list of urls and their new 301 destination.
<br>
[exampleE.COM...] ->
http://www.example.COM/accom_detail-PropertyID-64.htm
[exampleE.COM...] ->
http://www.example.COM/accom_detail-PropertyID-82.htm
[exampleE.COM...] ->
http://www.example.COM/accom_detail-PropertyID-46.htm
I really dont want to waste anyones time, so I thank you in advance.
If that is the case, then one rule will do them all:
RewriteRule ^web/urs/laySearchPackagesiid([0-9]+)nidblankdet1[^/]+/page//SearchPackages\.asp$ http://www.example.com/accom_detail-PropertyID-%1.htm [R=301,L]
That new URL plan might do with some improvement as well, since neither visitors nor search engines will "care" about any of the text in that URL except for the potentially-useful 'keywords' of "property" and possibly "desmonddeport".
You might actually consider retaining that "desmonddepord" string if it is a useful search keyword. If this is the case, you could *redirect* the long ugly .asp URL to something like "http://www.example.com/acdet-64/desmonddepord", and then internally *rewrite* requests for that URL to the filepath "/accom_detail-PropertyID-64.htm" -- or to whatever script-filepath you're actually using to generate that page. Links on your pages should point to the URL http://www.example.com/acdet-64/desmonddepord URL. (Note the very important distinction made here between URLs on the Web and filepaths inside your server; They are "associated, but not at all equivalent things.)
And note that there is no need to put ".htm" on any of the URLs -- Having gone through one "technology transition," two things should be fairly clear: Long ugly URLs are bad (imagine trying to read those .asp URLs aloud in a TV/radio ad), and changing the URLs just because you change the back-end server technology is also bad (and expensive in terms of time and lost ranking/traffic). So a good 'future-proofing' approach is to dump "filetypes" from page URLs now and go extensionless -- and this makes the URLs even shorter, too.
Jim