20140317 apache rewriting from one wordpress folder to another - plembo/onemoretech GitHub Wiki

title: Apache rewriting from one WordPress folder to another link: https://onemoretech.wordpress.com/2014/03/17/apache-rewriting-from-one-wordpress-folder-to-another/ author: phil2nc description: post_id: 7149 created: 2014/03/17 23:03:23 created_gmt: 2014/03/18 03:03:23 comment_status: closed post_name: apache-rewriting-from-one-wordpress-folder-to-another status: publish post_type: post

Apache rewriting from one WordPress folder to another

Just now renamed a blog running under WordPress in Multisite mode (subfolder) and wanted to redirect still trying to use the old url to the new. Apache rewrite recipe follows. This is a pretty basic mod_rewrite configuration as they go, but since it took me a few minutes to get it right I thought it might save someone else a bit of time. Once upon a time there was a blog called http://blogs.example.com/oldblog. After awhile its owners decided they'd rather call it http://blogs.example.com/newblog. Changing the blog name wasn't a big deal. All we had to do was dump the database using mysqldump[1], do a

perl -pi -e 's/oldblog/newblog/g' blogs.sql

and then reload the db[2] (or copy the searchreplacedb2.php script into the site root and use it to do the search and replace). Doing rewrites of WordPress urls can be a tricky business because so much of the "magic" involved in making WordPress work, particularly in multisite mode, is in some fairly involved rewrite rules embedded in the main .htaccess file in the root folder. As a result there's really no margin for error in syntax. For my solution the following lines were inserted in the Apache virtual host block for the blog, preferably after the statement:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} oldblog
    RewriteRule oldblog/(.*) /newblog/$1 [R=301,L]

The rewrite worked without the RewriteCond statement, but I think it's safer to include it. [1] The syntax for mysqldump would be something like:

mysqldump -u root -p --datatabase blogs >blogs.sql

[2] Reloading the db would be done using a statement like:

mysql -u root -p blogs <blogs.sql

Note: I really wanted to use superscript for these notes, but the font applied by this wordpress.com supplied theme was just too damn small. So I fell back to using bracketed numbers like we did back in the bad old days when TeX was the weapon of choice for computer-saavy grad students. I printed all the papers I wrote for my Masters degree on a daisy wheel printer (whose CP/M driver was the one and only piece of software I ever wrote in assembler -- in between trial calendar calls!) formatted with TeX for CP/M -- after composing them using Eric Meyer's VDE.

Copyright 2004-2019 Phil Lembo

⚠️ **GitHub.com Fallback** ⚠️