Best way to use mod_rewrite to replace WordPress pages with static files
        Posted  
        
            by David Moles
        on Server Fault
        
        See other posts from Server Fault
        
            or by David Moles
        
        
        
        Published on 2010-04-25T13:06:58Z
        Indexed on 
            2010/04/25
            13:13 UTC
        
        
        Read the original article
        Hit count: 290
        
apache2
|mod-rewrite
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?
© Server Fault or respective owner