Forum Moderators: phranque
[example.com...]
is now
[example.com...]
and
[example.com...]
has similarly become
[example.com...]
The "view" parameter in the new scheme is always the name of the page in the old scheme minus the '.cgi' part. I figure I need a mod_rewrite script to redirect people, but I have some sort of bizarre mental block against being able to use mod_rewrite properly and my scripts always end up throwing errors or impregnating the cat or something. Any help would be much appreciated.
/about.cgi /buildpage.cgi?view=about
/opinion.cgi /buildpage.cgi?view=opinion
This works best when there is no rhyme or reason the the filenames and there are just a few.
You must also include in the httpd.conf
RewriteEngine On
# check for those with query strings
RewriteMap oldlinks txt:/var/www/.htoldlinks
RewriteCond %{QUERY_STRING}!=""
RewriteCond %{REQUEST_URI}!=""
RewriteCond ${oldlinks:%{REQUEST_URI}?%{QUERY_STRING}¦NOT-FOUND}!=NOT-FOUND
RewriteRule ^.* ${oldlinks:%{REQUEST_URI}?%{QUERY_STRING}}? [R=301,L]# check for those without query strings
RewriteCond %{REQUEST_URI}!=""
RewriteCond ${oldlinks:%{REQUEST_URI}¦NOT-FOUND}!=NOT-FOUND
RewriteRule ^.* ${oldlinks:%{REQUEST_URI}} [R=301,L]
This is what works for me as I have a variety of static pages and old cfm pages with queries as well as directory structures that I have migrated. Your mileage may vary.
gergoe: Essentially all of the pages are being redirected to buildpage.cgi, but with "?view=somepage" appended to the end. Ideally what I'd like to be able to do is take any page (call it "oldpage.cgi") that isn't buildpage.cgi, extract the cgi name, strip off the ".cgi" at the end, and redirect it to buildpage.cgi?view=oldpage.
RewriteCond %{REQUEST_URI} ^/buildpage.cgi?view=(*.)$ [NC]
RewriteRule ^buildpage\.cgi$ http://www.example.com/buildpage.cgi?view=$1 [L]
RewriteCond %{REQUEST_URI} (/*.cgi)$ [NC]
RewriteRule (*.)\.cgi$ http://www.example.com/buildpage.cgi?view=$1 [L]
The second rule would be used to rewrite any requests for anyfile.cgi. The first rule is intended to prevent rewriting any request for buildpage.cgi, or, more accurately, to rewrite to iself, thus avoiding the second rule.
I'm no expert, and offer no claims of usability. But as a simple solution it might work.
RewriteEngine on
RewriteCond %{REQUEST_URI}!^/buildpage.cgi [NC]
RewriteRule ^/(.+)\.cgi$ /buildpage.cgi?view=$1 [QSA,R,L]
RewriteEngine on
RewriteCond %{REQUEST_URI}!buildpage.cgi [NC]
# parse out basename, but remember the fact
RewriteRule (.*)\.cgi$ $1 [C,E=WasCGI:yes]
# rewrite to buildpage.cgi if template exists
RewriteCond /home/example/example.com/templates/$1.txt -f
RewriteRule ^(.*)$ buildpage.cgi?view=$1 [S=1]
# else reverse the previous rewrite
RewriteCond %{ENV:WasCGI} ^yes$
RewriteRule ^(.*)$ $1.cgi [L]
Thanks again everyone for getting me on the right track.