How to rewrite with URL *and* query string

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

How to rewrite with URL *and* query string

03 Mar 2014, 12:42

Hi.

I have a system with a series of URLs that look like:

mqh/contact-form.html?CAT=xxx&STY=ENQ

- which are mapped to an ASP service.

The site owner now wants to remove some of the categories, so that e.g.

mqh/contact-form.html?CAT=car will map to page.gone?stat=410&typ=cat&cat=Wedding+Car+Hire

I thought the following would do it:
RewriteCond %{QUERY_STRING} ^cat=car.*$ [NC]
RewriteRule mqh/contact-form\.html page.gone?stat=410&typ=cat&cat=Wedding+Car+Hire [L,NC]

But instead it falls through that rule and triggers the enquiry form.

What am I missing, here?

(NB we're rewriting to page.gone instead of just directly throwing a 410 (gone) status because a later rule triggers the G with QSA set, which in turn calls custom410.asp, which captures the "cat=... " bit and puts detail in the page. Messy, but I can't think of a better way to do it).

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

03 Mar 2014, 15:13

Hello,

Strange. The rule looks okay. What is the enquiry form rule?
Can you take a snapshot of the logs for a testing request?

Regards

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

04 Mar 2014, 11:25

HeliconAndrew wrote:Hello,

Strange. The rule looks okay. What is the enquiry form rule?
Can you take a snapshot of the logs for a testing request?

Regards


The enquiry form rule is picked up by a general rule:
Code: Select all
#make active pages
RewriteRule mqh/(.*)\.(htm|html) mqh/default.asp?Category=mar-runs&service=$1 [L,NC,QSA,NS]


So, e.g.
Code: Select all
mqh/contact-form.html?CAT=xxx&STY=ENQ

Will go to:

Code: Select all
mqh/default.asp?category=mar-runs&service=contact-form&CAT=XXX&STY=ENQ

- and this is what is being served.

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

04 Mar 2014, 11:27

I'll see if I can capture some log data.

The problem is that it's a busy site. I *do* wish logging could be file-specific.

If I turn logging on, the log file gets huge within minutes.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

04 Mar 2014, 15:58

Of course the more generic rule gets served. You have the following options:

a. Put your new rule higher in the file than the inquiry rule
b. Add a restrictive condition for the inquiry rule. Something like: RewriteCond %{QUERY_STRING} ^$. So that it looks for an empty query string
c. Combine two above

Regards

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

06 Mar 2014, 08:53

Code: Select all
(2) init rewrite engine with requested uri /contact-form.html?cat=car
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request
(1) Htaccess process request d:\inetpub\wwwroot\marqueehire\website\.htaccess

That's the housekeeping out of the way.
Code: Select all
(3) applying pattern '.?' to uri 'contact-form.html'
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.com$'
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.marqueehireguide\.c
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.co\.uk
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.co\.uk$' =
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.co\.u
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.com$' => n
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.com$'

No canonicalisation needed
Code: Select all
(3) applying pattern '(.*\.html)' to uri 'contact-form.html'
(4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\contact-form.html
(5) map lookup FAILED: map=changes[txt] key=/contact-form.html
(4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched

Not a rewrite from the changes map
Code: Select all
(3) applying pattern 'mqh/contact-form\.html' to uri 'contact-form.html'
(3) applying pattern 'mqh/contact-form\.html?cat=bal(.*)' to uri 'contact-form.html'

Seem to have applied one rule but not the second one...

Code: Select all
(3) applying pattern 'page\.gone' to uri 'contact-form.html'
(3) applying pattern '.*\.do$' to uri 'contact-form.html'
(3) applying pattern '(.*\.html)' to uri 'contact-form.html'
(4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\contact-form.html
(5) map lookup FAILED: map=notcurrent[txt] key=/contact-form.html
(4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
(3) applying pattern '(.*\.html)' to uri 'contact-form.html'
(5) map lookup FAILED: map=gone[txt] key=/contact-form.html
(4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
(3) applying pattern '^index\.html' to uri 'contact-form.html'
(3) applying pattern 'catering-equipment-hire-c898\.html(.+)' to uri 'contact-form.h
(3) applying pattern 'mqha/$' to uri 'contact-form.html'
(3) applying pattern 'mqh/(.*)\.(htm|html)' to uri 'contact-form.html'
(3) applying pattern 'mqha/(.*)\.(htm|html)' to uri 'contact-form.html'
(3) applying pattern '(.*)-(i[0-9]+)\.html$' to uri 'contact-form.html'
(3) applying pattern 'postcode-search.html$' to uri 'contact-form.html'
(3) applying pattern 'photos/small-.*-(i[0-9]+)-(.*)\.jpg' to uri 'contact-form.html
(3) applying pattern 'photos/.*-(i[0-9]+)-(.*)\.jpg' to uri 'contact-form.html'
(3) applying pattern 'music-for-your-event-in-(.*)-c([0-9]+)\.html$' to uri 'contact
(3) applying pattern 'advertise-with-us-c595\.html' to uri 'contact-form.html'
(3) applying pattern '.*-c([0-9]+)\.html$' to uri 'contact-form.html'
(3) applying pattern 'mar-user/(.*)' to uri 'contact-form.html'
(3) applying pattern 'outlinks/(.*)\.html' to uri 'contact-form.html'
(3) applying pattern 'logo-([0-9]+ICE[0-9]+_[0-9]+)\.gif' to uri 'contact-form.html'


Falls through all the rest and throws a 404.

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

06 Mar 2014, 15:37

HeliconAndrew wrote:Of course the more generic rule gets served. You have the following options:

a. Put your new rule higher in the file than the inquiry rule
b. Add a restrictive condition for the inquiry rule. Something like: RewriteCond %{QUERY_STRING} ^$. So that it looks for an empty query string
c. Combine two above

Regards


Aha. I see what I did. I created a rule that redirects to "page.gone" and then put an L flag on it. So it never hits the rule that sets a "410- Gone" status and triggers the custom410.asp file. :oops:

:idea: Getting it, now.

I think I need to review what the various flags do!


User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

13 Mar 2014, 16:38

I'm seriously missing something now.

I have two rules, neither of them seemingly that complex.
One of them causes a 404.
The other falls through and attempts to serve a page,

More interestingly, the custom404 isn't working any more (last rule in the ruleset sends anything not matching either a higher rule or a real file to a service, custom404 that logs what's being sought and subsequently causes the custom404.asp to be triggered. Except that, since March 1st, it turns out that it's not doing so. We get the 404, but it's being triggered directly and not via the rewrite rule (so it's not logging, and it's not showing the URI that was being sought).

I have to assume that it's due to these new rules, but I'm getting increasingly bewildered.

Any thoughts?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

16 Mar 2014, 13:00

Have you looked at the rewrite.log and error.log?

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

27 Mar 2014, 07:55

HeliconAndrew wrote:Have you looked at the rewrite.log and error.log?


Sure- the problem is that this is a live site, on a machine with multiple sites and the logs fill up really quickly.

It's hard to see what's going on.

It would be *massively* helpful if you could turn logging on and off at a domain/site level.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

27 Mar 2014, 12:32

Unfortunately this is not that easy. Besides logging was created only for us, for debugging purposes.

So there's no other way but to search through the log for a testing request and see the section where it is processed.

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

27 Mar 2014, 16:03

I have the custom404 working again- another typo. I'm really growing to dislike the editor. :(

The only issue I have now is the rules that should force the contact-form.html to rewrite to page.gone when the category is one of the discontinued ones.

They *both* now throw a 404, which is interesting...


Code: Select all
(2) init rewrite engine with requested uri /mqh/contact-form.html?CAT=bal&STY=ENQ
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (1) Htaccess process request
 (1) Htaccess process request d:\inetpub\wwwroot\marqueehire\website\.htaccess
 (3) applying pattern '.?' to uri 'mqh/contact-form.html'
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.com$' => not-matched
 (3) applying pattern '(.*\.html)' to uri 'mqh/contact-form.html'
 (4) RewriteCond: input='\\?\d:\inetpub\wwwroot\MarqueeHire\website\contact-form.html' pattern='!-f' => matched
 (5) map lookup FAILED: map=changes[txt] key=/mqh/contact-form.html
 (4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
 (3) applying pattern 'mqh/contact-form\.html' to uri 'mqh/contact-form.html'
 (4) RewriteCond: input='CAT=bal&STY=ENQ' pattern='^cat=car.*$' => not-matched
 (3) applying pattern 'mqh/contact-form\.html' to uri 'mqh/contact-form.html'
 (4) RewriteCond: input='CAT=bal&STY=ENQ' pattern='^cat=bal.*$' => matched
 (1) Rewrite URL to >> /page.gone?stat=410&typ=cat&cat=Balloon+Decoration
 (2) rewrite 'mqh/contact-form.html' -> '/page.gone?stat=410&typ=cat&cat=Balloon+Decoration'
 (2) internal redirect with /page.gone?stat=410&typ=cat&cat=Balloon+Decoration [INTERNAL REDIRECT]


So- we've successfully redirected the URL to "page.gone" but...


Code: Select all
 (1) Htaccess process request d:\inetpub\wwwroot\marqueehire\website\.htaccess
 (3) applying pattern '.?' to uri 'page.gone'
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.com$' => not-matched
 (3) applying pattern '(.*\.html)' to uri 'page.gone'
 (3) applying pattern 'mqh/contact-form\.html' to uri 'page.gone'
 (3) applying pattern 'mqh/contact-form\.html' to uri 'page.gone'
 (3) applying pattern '(.*\.html)' to uri 'page.gone'
 (3) applying pattern 'page\.gone' to uri 'page.gone'
 (3) applying pattern '.*\.do$' to uri 'page.gone'
 (3) applying pattern '(.*\.html)' to uri 'page.gone'
 (3) applying pattern 'mqha/$' to uri 'page.gone'
 (3) applying pattern 'mqh/(.*)\.(htm|html)' to uri 'page.gone'
 (3) applying pattern 'mqha/(.*)\.(htm|html)' to uri 'page.gone'
 (3) applying pattern '(.*)-(i[0-9]+)\.html$' to uri 'page.gone'
 (3) applying pattern 'postcode-search.html$' to uri 'page.gone'
 (3) applying pattern 'photos/small-.*-(i[0-9]+)-(.*)\.jpg' to uri 'page.gone'
 (3) applying pattern 'photos/.*-(i[0-9]+)-(.*)\.jpg' to uri 'page.gone'
 (3) applying pattern 'music-for-your-event-in-(.*)-c([0-9]+)\.html$' to uri 'page.gone'
 (3) applying pattern 'advertise-with-us-c595\.html' to uri 'page.gone'
 (3) applying pattern '.*-c([0-9]+)\.html$' to uri 'page.gone'
 (3) applying pattern '^index\.html' to uri 'page.gone'
 (3) applying pattern 'catering-equipment-hire-c898\.html(.+)' to uri 'page.gone'
 (3) applying pattern 'mar-user/(.*)' to uri 'page.gone'
 (3) applying pattern 'outlinks/(.*)\.html' to uri 'page.gone'
 (3) applying pattern 'logo-([0-9]+ICE[0-9]+_[0-9]+)\.gif' to uri 'page.gone'
 (3) applying pattern '(.*)' to uri 'page.gone'
 (4) RewriteCond: input='\\?\d:\inetpub\wwwroot\MarqueeHire\website\contact-form.html' pattern='!-d' => matched
 (4) RewriteCond: input='\\?\d:\inetpub\wwwroot\MarqueeHire\website\contact-form.html' pattern='!-f' => matched

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

27 Mar 2014, 16:36

And here's one that *does* work:

Code: Select all
(2) init rewrite engine with requested uri /celebration-rolls-royce-i659094.html
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (1) Htaccess process request
 (1) Htaccess process request d:\inetpub\wwwroot\marqueehire\website\.htaccess
 (3) applying pattern '.?' to uri 'celebration-rolls-royce-i659094.html'
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.com$' => not-matched
 (3) applying pattern '(.*\.html)' to uri 'celebration-rolls-royce-i659094.html'
 (4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\celebration-rolls-royce-i659094.html' pattern='!-f' => matched
 (5) map lookup FAILED: map=changes[txt] key=/celebration-rolls-royce-i659094.html
 (4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
 (3) applying pattern 'mqh/contact-form\.html' to uri 'celebration-rolls-royce-i659094.html'
 (3) applying pattern 'mqh/contact-form\.html' to uri 'celebration-rolls-royce-i659094.html'
 (3) applying pattern '(.*\.html)' to uri 'celebration-rolls-royce-i659094.html'
 (5) map lookup OK: map=g[txt] key=/celebration-rolls-royce-i659094.html -> val=page.gone?stat=410&ptype=cat&cat=Wedding Car Hire
 (4) RewriteCond: input='page.gone?stat=410&ptype=cat&cat=Wedding Car Hire' pattern='NOT_FOUND' => matched
 (5) map lookup OK: map=g[txt] key=/celebration-rolls-royce-i659094.html -> val=page.gone?stat=410&ptype=cat&cat=Wedding Car Hire
 (1) Rewrite URL to >> /page.gone?stat=410&ptype=cat&cat=Wedding%20Car%20Hire
 (2) rewrite 'celebration-rolls-royce-i659094.html' -> '/page.gone?stat=410&ptype=cat&cat=Wedding%20Car%20Hire'
 (3) applying pattern 'page\.gone' to uri 'page.gone'
 (2) explicitly forcing redirect with http://www.marqueehireguide.com/page.gone?stat=410&ptype=cat&cat=Wedding%20Car%20Hire
 (2) forcing responsecode 410 for /page.gone?stat=410&ptype=cat&cat=Wedding%20Car%20Hire
 (2) internal redirect with /page.gone?stat=410&ptype=cat&cat=Wedding%20Car%20Hire [INTERNAL REDIRECT]


Interestingly, this *does* match page.gone with page\.gone

I can't for the life of me see the difference between this and the previous rule that doesn't match

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

01 Apr 2014, 00:17

I can see that both hit the rules and resulted in redirect. But first one continued to reprocess. Try using [NS]-flag.
This is weird, but it's really confusing. The common troubleshooting technique would be to comment out a part of config and see if it fixes it. Gradually uncommenting the rules would reveal the traitor.

Regards

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

11 Apr 2014, 07:09

HeliconAndrew wrote:I can see that both hit the rules and resulted in redirect. But first one continued to reprocess. Try using [NS]-flag.
This is weird, but it's really confusing. The common troubleshooting technique would be to comment out a part of config and see if it fixes it. Gradually uncommenting the rules would reveal the traitor.

Regards


The trouble is, it would also mess up a busy running site!

I'm getting more weird things happening now:

There's a rule that validates these "magic" rules:

After some stuff to canonicalise domains, the first three rulesets are:

Code: Select all
#Rewrite Changed names with a rewritemap
RewriteMap changes txt:changes.map [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ${changes:%{REQUEST_URI}|NOT_FOUND} !NOT_FOUND
RewriteRule (.*\.html) ${changes:%{REQUEST_URI}} [L,NS,NC,R=301,QSA]

#magic category lookups
RewriteMap magic-c txt:magic-c.map [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ${magic-c:%{REQUEST_URI}|NOT_FOUND} !NOT_FOUND
RewriteRule .*-c([0-9]+)\.html$ /mqh/default.asp?category=mar-runs&service=make-page&magic=$1&oqs=$& [L,NC,QSA,NS]

# make advertiser page lookups
RewriteMap magic-i txt:magic-i.map [NC]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond ${magic-i:%{REQUEST_URI}|NOT_FOUND} !NOT_FOUND
RewriteRule (.*)-(i[0-9]+)\.html$ /mqh/default.asp?category=mar-runs&service=MakeAdPage&magic=$2&oqs=$1 [L,NC,QSA,NS]


Which is fine.

Here's one working-

Code: Select all
(2) init rewrite engine with requested uri /marquee-hire-in-bedfordshire-c36.html
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request
(1) Htaccess process request d:\inetpub\wwwroot\marqueehire\website\.htaccess
(3) applying pattern '.?' to uri 'marquee-hire-in-bedfordshire-c36.html'
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.com$' => not-matched
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.marqueehireguide\.co\.uk$' => not-matched
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.co\.uk$' => not-matched
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.co\.uk$' => not-matched
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.co\.uk$' => not-matched
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.com$' => not-matched
(4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.com$' => not-matched
(3) applying pattern '(.*\.html)' to uri 'marquee-hire-in-bedfordshire-c36.html'
(4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\marquee-hire-in-bedfordshire-c36.html' pattern='!-f' => matched
(5) map lookup FAILED: map=changes[txt] key=/marquee-hire-in-bedfordshire-c36.html
(4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
(3) applying pattern '.*-c([0-9]+)\.html$' to uri 'marquee-hire-in-bedfordshire-c36.html'
(4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\marquee-hire-in-bedfordshire-c36.html' pattern='!-f' => matched
(5) map lookup OK: map=m[txt] key=/marquee-hire-in-bedfordshire-c36.html -> val=36
(4) RewriteCond: input='36' pattern='NOT_FOUND' => matched
(1) Rewrite URL to >> /mqh/default.asp?category=mar-runs&service=make-page&magic=36&oqs=marquee-hire-in-bedfordshire-c36.html
(2) rewrite 'marquee-hire-in-bedfordshire-c36.html' -> '/mqh/default.asp?category=mar-runs&service=make-page&magic=36&oqs=marquee-hire-in-bedfordshire-c36.html
(2) internal redirect with /mqh/default.asp?category=mar-runs&service=make-page&magic=36&oqs=marquee-hire-in-bedfordshire-c36.html [INTERNAL REDIRECT]


And here's one not:

Code: Select all
(2) init rewrite engine with requested uri /West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (1) Htaccess process request
 (1) Htaccess process request d:\inetpub\wwwroot\marqueehire\website\.htaccess
 (3) applying pattern '.?' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^marqueehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.co\.uk$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^thehireguide\.com$' => not-matched
 (4) RewriteCond: input='www.marqueehireguide.com' pattern='^www\.thehireguide\.com$' => not-matched
 (3) applying pattern '(.*\.html)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html' pattern='!-f' => matched
 (5) map lookup FAILED: map=changes[txt] key=/West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html
 (4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
 (3) applying pattern '.*-c([0-9]+)\.html$' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html' pattern='!-f' => matched
 (5) map lookup FAILED: map=magic-c[txt] key=/West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html
 (4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
 (3) applying pattern '(.*)-(i[0-9]+)\.html$' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'mqh/contact-form\.html' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'mqh/contact-form\.html' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern '(.*\.html)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (5) map lookup FAILED: map=gone[txt] key=/West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html
 (4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
 (3) applying pattern '(.*\.html)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html' pattern='!-f' => matched
 (5) map lookup FAILED: map=notcurrent[txt] key=/West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html
 (4) RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
 (3) applying pattern 'page\.gone' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern '.*\.do$' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'mqha/$' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'mqh/(.*)\.(htm|html)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'mqha/(.*)\.(htm|html)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'postcode-search.html$' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'photos/small-.*-(i[0-9]+)-(.*)\.jpg' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'photos/.*-(i[0-9]+)-(.*)\.jpg' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'music-for-your-event-in-(.*)-c([0-9]+)\.html$' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'advertise-with-us-c595\.html' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern '^index\.html' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'catering-equipment-hire-c898\.html(.+)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'mar-user/(.*)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'outlinks/(.*)\.html' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern 'logo-([0-9]+ICE[0-9]+_[0-9]+)\.gif' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (3) applying pattern '(.*)' to uri 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html' pattern='!-d' => matched
 (4) RewriteCond: input='\\?\D:\inetpub\wwwroot\MarqueeHire\website\West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html' pattern='!-f' => matched
 (1) Rewrite URL to >> /mqh/default.asp?Category=mar-runs&service=custom404&oqs=West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html
 (2) rewrite 'West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html' -> '/mqh/default.asp?Category=mar-runs&service=custom404&oqs=West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html'
 (2) internal redirect with /mqh/default.asp?Category=mar-runs&service=custom404&oqs=West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html [INTERNAL REDIRECT]


And here is a section of magic-c.map:

Code: Select all
/rutland-mixologists-mobile-cocktail-bar-hire-c2060.html 2060
/West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html 2061
/Yorkshire-East-mixologists-mobile-cocktail-bar-hire-c2062.html 2062
/Yorkshire-North-mixologists-mobile-cocktail-bar-hire-c2063.html 2063
/Yorkshire-South-mixologists-mobile-cocktail-bar-hire-c2064.html 2064
/Yorkshire-West-mixologists-mobile-cocktail-bar-hire-c2065.html 2065


I'm *really* not understanding why some are matching and some not.. apart from the actual text involved, they seem to be identical processes, but one matches and one not. Is there an undocumented character limit on mapfiles?

My client is getting seriously cross with me, and asking about can we switch to a different rewrite tech?

How can I even debug this in any more detail?

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

11 Apr 2014, 22:46

The key thing here is:

Code: Select all
(5) map lookup FAILED: map=magic-c[txt] key=/West-Sussex-mixologists-mobile-cocktail-bar-hire-c2061.html


Which is odd- because that's clearly there in the map file.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

13 Apr 2014, 23:07

All the '/' and '.' in place? Other typos? since you were complaining about the font? ;)

Permissions? All other entries work fine?

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: How to rewrite with URL *and* query string

17 Apr 2014, 12:56

You got me. I found some typos.

*not* all other entries work fine, though: I've noticed that the ones I originally asked about still don't work, though I've fixed the related 401 issue.

I have a rule that says:

Code: Select all
#divert removed category searches
RewriteCond %{QUERY_STRING} ^cat=car.*$ [NC]
RewriteRule mqh/contact-form\.html page.gone?stat=410&typ=cat&cat=Wedding+Car+Hire [L,NC]

RewriteCond %{QUERY_STRING} ^cat=bal.*$ [NC]
RewriteRule mqh/contact-form\.html page.gone?stat=410&typ=cat&cat=Balloon+Decoration [L,NC]


And later:

Code: Select all
# flag up "gone" pages from removed categories
RewriteRule page\.gone - [G,L,NS,QSA]


Which seems not to work, though others diverted by *this* rule do:

Code: Select all
#handle removed categories
RewriteMap gone txt:gone.map [NC]
RewriteCond ${gone:%{REQUEST_URI}|NOT_FOUND} !NOT_FOUND
RewriteRule (.*\.html) ${gone:%{REQUEST_URI}} [NC,QSA]


gone.map includes mappings such as:
Code: Select all
wedding-car-hire-c1424.html page.gone?stat=410&ptype=cat&cat=Wedding Car Hire


So, if it's triggered by "gone.map", it seems to work fine:

When I'm testing on the query-string as well, it seems to fail.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: How to rewrite with URL *and* query string

20 Apr 2014, 22:57

In case you want to have "mqh/contact-form.html?cat=car" to match the rewrite rule and then match the GONE rule, simply remove the [L] flag. OR am I missing anything?

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 14 guests