Using rewrite to move and refactor a site...
10 posts
• Page 1 of 1
Using rewrite to move and refactor a site...
Hi,
I have a site where the content is being moved from one platform to another. That's not too bad, except there are also some changes.
So, there are three types of URL, *all* containing a "magic number".
All the URLs end in -c(number).html
The three types are:
- unchanged pages; if we see them, we just want to serve the page.
- changed pages: if we see them, we want to redirect to a new version (thinking of a rewrite map, here: there are lots).
- dynamic pages: these pages *look* like static pages, but are actually served from an ASP process.
So - can I use a RewriteCond to say - just serve this if it exists?
And then a RewriteMap to redirect the changed ones - with a 301?
And then a default of the ASP process?
Is it possible to have a RewriteMap with no default value?
E.g.
RewriteMap magic txt:D:/website/magic.map
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L,NC,QSA,NS]
RewriteRule .*-c([0-9]+)\.html$ ${magic:$1} [R=301,NC,L]
RewriteRule .*-c([0-9]+)\.html$ mqh/default.asp?category=mar-runs&service=make-page&magic=$1 [L,NC,QSA,NS]
The problem here is that I want the changed URLs to be redirected (301) but not the dynamic ones.
I have a site where the content is being moved from one platform to another. That's not too bad, except there are also some changes.
So, there are three types of URL, *all* containing a "magic number".
All the URLs end in -c(number).html
The three types are:
- unchanged pages; if we see them, we just want to serve the page.
- changed pages: if we see them, we want to redirect to a new version (thinking of a rewrite map, here: there are lots).
- dynamic pages: these pages *look* like static pages, but are actually served from an ASP process.
So - can I use a RewriteCond to say - just serve this if it exists?
And then a RewriteMap to redirect the changed ones - with a 301?
And then a default of the ASP process?
Is it possible to have a RewriteMap with no default value?
E.g.
RewriteMap magic txt:D:/website/magic.map
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L,NC,QSA,NS]
RewriteRule .*-c([0-9]+)\.html$ ${magic:$1} [R=301,NC,L]
RewriteRule .*-c([0-9]+)\.html$ mqh/default.asp?category=mar-runs&service=make-page&magic=$1 [L,NC,QSA,NS]
The problem here is that I want the changed URLs to be redirected (301) but not the dynamic ones.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Using rewrite to move and refactor a site...
Hello,
- Is it possible to have a RewriteMap with no default value?
- you mean NULL? No, you can't have an empty value.
- The problem here is that I want the changed URLs to be redirected (301) but not the dynamic ones.
- The dynamic URLs are the third type, right? They are served by the third rule... The rule itself looks like it's a rewrite rule, not a 301-redirect. So i'm not sure where the problem is. Does it get redirected?
Regards
Andrew
- Is it possible to have a RewriteMap with no default value?
- you mean NULL? No, you can't have an empty value.
- The problem here is that I want the changed URLs to be redirected (301) but not the dynamic ones.
- The dynamic URLs are the third type, right? They are served by the third rule... The rule itself looks like it's a rewrite rule, not a 301-redirect. So i'm not sure where the problem is. Does it get redirected?
Regards
Andrew
Re: Using rewrite to move and refactor a site...
When I switch on the redirect rules, I get peculiar things happening.
The site uses a platform called CoolICE, which has active content accessed via an ASP page (classic ASP, not ASP.net).
Active pages have a form that goes:
<host>/<gateway>/default.asp?category=<category>&service=<service>&...
The <gateway> segment matches a virtual directory set up in IIS.
The first thing I've done is to remap the active services to hide the detail:
#default doc for VDirs
RewriteRule mqha/$ mqha/default.asp?category=mar-runs&service=a-menu [NC]
#make active pages
RewriteRule mqh/(.*)\.(htm|html) mqh/default.asp?Category=mar-runs&service=$1 [L,NC,QSA,NS]
RewriteRule mqha/(.*)\.(htm|html) mqha/default.asp?Category=mar-runs&service=$1 [L,NC,QSA,NS]
So e.g. mqh/contact-form.html?cat=MAR&sty=ENQ -> mqh/default.asp?category=mar-runs&service=contact-form&cat=MAR&sty=ENQ
(the mqha is the admin side, which is fine).
The next thing I do is remap some detail pages:
# make advertiser page lookups
RewriteRule (.*)-(i[0-9]+)\.html$ /mqh/default.asp?category=mar-runs&service=MakeAdPage&magic=$2&stub=$1 [L,NC,QSA,NS]
Then some redirects of renamed pages, by pattern:
#rewrite music pages
RewriteRule music-for-your-event-in-(.*)-c([0-9]+)\.html$ mobile-discos-djs-$1-c$2.html [NC,R=301,NS]
The next thing I want to do is to capture any "real" static pages:
I think this *should* work, but apparently it doesn't:
RewriteCond %{REQUEST_URI} -f
RewriteRule .? - [NC,L,NS,QSA]
Then I want to trap any redirects from the "magic" map file.
RewriteMap magic txt:D:/inetpub/wwwroot/marqueehire/magic.map
RewriteCond %{REQUEST_URI} ^.*-(c[0-9]+)\.html$
RewriteCond ${magic:%1|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule .? ${magic:%1} [L,NC,QSA,R=301]
When I do this, though, it seems to tell me that some real URLs are unfindable and warns about redirect loops.
Lastly, any URL with a "magic" code that's *not* a real file should be picked up:
# magic category rules..
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*-c([0-9]+)\.html$ mqh/default.asp?category=mar-runs&service=make-page&magic=$1&oqs=$& [L,NC,QSA,NS]
After that there's just some specialised odds and bits.
Am I missing something massive?
The site uses a platform called CoolICE, which has active content accessed via an ASP page (classic ASP, not ASP.net).
Active pages have a form that goes:
<host>/<gateway>/default.asp?category=<category>&service=<service>&...
The <gateway> segment matches a virtual directory set up in IIS.
The first thing I've done is to remap the active services to hide the detail:
#default doc for VDirs
RewriteRule mqha/$ mqha/default.asp?category=mar-runs&service=a-menu [NC]
#make active pages
RewriteRule mqh/(.*)\.(htm|html) mqh/default.asp?Category=mar-runs&service=$1 [L,NC,QSA,NS]
RewriteRule mqha/(.*)\.(htm|html) mqha/default.asp?Category=mar-runs&service=$1 [L,NC,QSA,NS]
So e.g. mqh/contact-form.html?cat=MAR&sty=ENQ -> mqh/default.asp?category=mar-runs&service=contact-form&cat=MAR&sty=ENQ
(the mqha is the admin side, which is fine).
The next thing I do is remap some detail pages:
# make advertiser page lookups
RewriteRule (.*)-(i[0-9]+)\.html$ /mqh/default.asp?category=mar-runs&service=MakeAdPage&magic=$2&stub=$1 [L,NC,QSA,NS]
Then some redirects of renamed pages, by pattern:
#rewrite music pages
RewriteRule music-for-your-event-in-(.*)-c([0-9]+)\.html$ mobile-discos-djs-$1-c$2.html [NC,R=301,NS]
The next thing I want to do is to capture any "real" static pages:
I think this *should* work, but apparently it doesn't:
RewriteCond %{REQUEST_URI} -f
RewriteRule .? - [NC,L,NS,QSA]
Then I want to trap any redirects from the "magic" map file.
RewriteMap magic txt:D:/inetpub/wwwroot/marqueehire/magic.map
RewriteCond %{REQUEST_URI} ^.*-(c[0-9]+)\.html$
RewriteCond ${magic:%1|NOT_FOUND} !NOT_FOUND [NC]
RewriteRule .? ${magic:%1} [L,NC,QSA,R=301]
When I do this, though, it seems to tell me that some real URLs are unfindable and warns about redirect loops.
Lastly, any URL with a "magic" code that's *not* a real file should be picked up:
# magic category rules..
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*-c([0-9]+)\.html$ mqh/default.asp?category=mar-runs&service=make-page&magic=$1&oqs=$& [L,NC,QSA,NS]
After that there's just some specialised odds and bits.
Am I missing something massive?
Re: Using rewrite to move and refactor a site...
HeliconAndrew wrote:Hello,
- Is it possible to have a RewriteMap with no default value?
- you mean NULL? No, you can't have an empty value.
- The problem here is that I want the changed URLs to be redirected (301) but not the dynamic ones.
- The dynamic URLs are the third type, right? They are served by the third rule... The rule itself looks like it's a rewrite rule, not a 301-redirect. So i'm not sure where the problem is. Does it get redirected?
Regards
Andrew
The above set of rules don't work- previously working pages stop working completely and get stuck in a redirect loop - I've had to back out that code completely.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Using rewrite to move and refactor a site...
I think it's time to look at the logs. Did you say you had trouble making it work?
Please, follow the FAQ to enable logging. And provide us with the rewrite.log for the testing request.
Regards
Andrew
Please, follow the FAQ to enable logging. And provide us with the rewrite.log for the testing request.
Regards
Andrew
Re: Using rewrite to move and refactor a site...
HeliconAndrew wrote:I think it's time to look at the logs. Did you say you had trouble making it work?
Please, follow the FAQ to enable logging. And provide us with the rewrite.log for the testing request.
Regards
Andrew
Was just a permissions issue. I've moved the log to a different location and given all users write permission and it now works well.
Re: Using rewrite to move and refactor a site...
HeliconAndrew wrote:I think it's time to look at the logs. Did you say you had trouble making it work?
Please, follow the FAQ to enable logging. And provide us with the rewrite.log for the testing request.
Regards
Andrew
One of the server administrators added a redirect rule to the *IIS* rewrite module, without thinking- and all the active pages stopped working, with a 500 internal server error.
The client has been using ISAPI_REWRITE since before IIS had a rewrite module!
The client's manager is now asking why we have ISAPI_REWRITE when IIS can do this "natively" - is there a good answer for him? What does it do better, or do at all, that IIS can't? I'm not sure why he cares, as they bought the licence some time back....
Re: Using rewrite to move and refactor a site...
HeliconAndrew wrote:I think it's time to look at the logs. Did you say you had trouble making it work?
Please, follow the FAQ to enable logging. And provide us with the rewrite.log for the testing request.
Regards
Andrew
I think what I'm going to do is to copy the necessary rules to another domain and duplicate the site- the site is now (in a limited way) live, and we don't want any bizarre goings on while we fix this issue. It will take me a little time to duplicate a subset of the code.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Using rewrite to move and refactor a site...
The client's manager is now asking why we have ISAPI_REWRITE when IIS can do this "natively" - is there a good answer for him? What does it do better, or do at all, that IIS can't? I'm not sure why he cares, as they bought the licence some time back....
ISAPI_Rewrite was designed to allow people from Unix world feel comfortable when creating rules for IIS.
We've never made a real comparison of ISAPI native rewriter and ISAPI_Rewrite, because our main goal was to create Apache analog with .NET support. Here's compatibility chart
So the main difference between ISAPI_Rewrite and IIS rewriter would be the syntax, which is in our case 99% Apache compatible.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Using rewrite to move and refactor a site...
I think what I'm going to do is to copy the necessary rules to another domain and duplicate the site- the site is now (in a limited way) live, and we don't want any bizarre goings on while we fix this issue. It will take me a little time to duplicate a subset of the code.
Please, provide the rewrite.log for the testing request and we'll figure out the problem.
Regards
Andrew
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 57 guests