[clue-tech] Simple (?) mod_rewrite problem

Jed S. Baer thag at frii.com
Sat Nov 18 19:46:27 MST 2006


On Sat, 18 Nov 2006 18:45:22 -0700
Jed S. Baer wrote:

> So, I'm trying to use mod_rewrite from an .htaccess file,
> which looks pretty simple for my purposes. So, here's the .htaccess
> file.
> 
> Options FollowSymLinks
> RewriteEngine On
> RewriteRule .*index\.php\?id=P([0-9]+)
> http://freedomsight.net/index.php?p=$1 [R=permanent,L]
> 
> Where the URL to be rewritten is of the form:
> http://s88369986.onlinehome.us/freedomsight/index.php?id=P1928
> and all I need to do is capture the trailing digits, to plug into the
> new URL.

  [snip] 

> But I'm beginning to
> think that the "URL" (uh, so to speak) which the pattern is used against
> is just the path portion of the URL, and doesn't include paramters.

Well, that's in fact the problem. The solution is to use RewriteCond:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id\=P([0-9]+)$
RewriteRule index\.php http://freedomsight.net/index.php?p=%1
[R=permanent,L]
RewriteRule index.php http://freedomsight.net/ [R=permanent,L]

The 2nd RewriteRule catches URLs with no "query string".

Other URLs, once I've wiped out the blog, I don't want to redirect -- why
send the comment spambots to the new place? (They'll find it soon enough
anyway, unfortunately.)

jed
-- 
http://freedomsight.net/
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier



More information about the clue-tech mailing list