0

Here's the situation: I've got an old WordPress installation that I'd like to archive as static files, but I'd also like to preserve old URLs. I've already created the static archive with wget and sorted out the filenames and links. Now I'd like to configure Apache to intercept requests for the old dynamic URL and replace them with the new static one, e.g.:

http://www.example.org/log/?p=1234

or

http://www.example.org/log/index.php?p=1234

should redirect to

http://www.example.org/log/archives/1234.html

I've tried adding the following to the VirtualHost config for example.org, but to no effect -- I just get the PHP page.

RewriteCond %{REQUEST_URI} /log/
RewriteCond %{QUERY_STRING} p=([^&;]*)
RewriteRule ^/$ http://%{SERVER_NAME}/log/archives/%1.html [R,L]

I've enabled logging and I can see what look like other rules being applied, but not this one. None of my other guesses at match patterns for %{REQUEST_URI} seem to have any effect either (log, log/, log.*, even .*).

I'm new to mod_rewrite and this is mostly cargo cult, so I'm pretty sure I've gotten it wrong. Anyone know what I should be doing here?

1 Answer 1

1

Try Changing RewriteRule ^/$ to RewriteRule ^/log/*$

As it is, your rule will never match anything because

RewriteCond %{REQUEST_URI} /log/

States that the URL must contain /log/ however

RewriteRule ^/$...

Will only match / exactly -- that is, the top level directory.

2
  • Thanks! Exactly right, and stupid of me. On a related note, do you know if there's a way I can strip the query string from the redirected URL? May 4, 2010 at 7:03
  • Well, I'm not sure. I would have expected the query string to have been stripped given the RewriteRule you provided... sounds like you should post that as a new question :-)
    – Josh
    May 4, 2010 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .