Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple RewriteRule not working 1

Status
Not open for further replies.

thost71

MIS
Sep 13, 2006
2
US
Hi all,

I'm new to mod_rewrite but have managed to set up a few rules which are working just fine, so I know it's working and that I have a basic grasp of what I'm doing. I've also been using perl for many years and am fairly proficient with regular expressions.

There's one rule which just isn't working, though. I've tried many variations of it and tested it inside a perl script, and I know I've got it right, but for some reason, mod_rewrite is ignoring it or not matching it. Here's the rule:

Code:
RewriteRule ^foobar\.plx\?ID=([0-9]+)$ /path/to/script.php?action=foobar&ID=$1

An example URL is along the lines of:
Code:
[URL unfurl="true"]http://www.ourdomain.tld/foobar.plx?ID=123456789[/URL]
and we would want it to load:
Code:
[URL unfurl="true"]http://www.ourdomain.tld/path/to/script.php?action=foobar&ID=123456789[/URL]

The .plx link is from a LONG time ago when we were running a perl version of the software on an NT server. There are hundreds of people linking to thar particular .plx file, which is why I need to do the rewrite.

Any thoughts? Is there something blatantly obvious that I've just missed? This is killing me and is one of the last things to resolve before the new version goes live, so my time is running out.

TIA,
St-
 
I see a couple of possibilities, but I'm grasping at straws a bit also... I haven't hacked mod_rewrite in some time.

I see that you're starting the rule with "^" which means 'the beginning of the line' in regexp...

So, if the expression text begins with "/" you won't match.

I also note your use of ([0-9]+)
I think you can also write that as something like
(\d{1,}) to match one or more digits. That assumes perl rules on regex apply.

Sorry, this is possibly a half-ass answer, but maybe it'll help.
D.



D.E.R. Management - IT Project Management Consulting
 
I've been playing with this for a while and can't make any headway. It seems that mod_rewrite ignores completely GET-method variables on the URI and I can't seem to get the module to change its mind on this.

One workaround I might suggest is changing the line in http.conf:

AddType application/x-httpd-php .php

to:

AddType application/x-httpd-php .php .plx


Then create the script foobar.plx:

Code:
<?php
header ('Location: /show_get.php?ID=' . $_GET['ID']);
?>

And let PHP redirect your users as necessary.



Want the best answers? Ask the best questions! TANSTAAFL!
 
I'm doing something similar with another rule, using mod_rewrite to rewrite a URL to a perl script which does basically what you're describing above. I was hoping to avoid that, though, as it seems like it should work this way. The other rule doesn't use GET data, though - looks like you may have nailed it.

<time spent googling around>

Got it! Here's the rule I'm using, which works perfectly:

Code:
RewriteRule foobar\.plx /path/to/script.php?action=foobar&?%{QUERY_STRING} [L]

Thanks to all for the suggestions!

St-

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top