Rewriting urls with mod rewrite and .htaccess, and wordpress.

Every time I do anything on this blog I run into this problem.  UK2 (who host me) have one public_html folder for euphy.co.uk, and then subfolders for polargraph.co.uk and my other domains.  This is just the way the product is structured – the other domains are addons to the original.

But the problem with it is that I can easily choose where the other domains get their source from.  So I can easily change polargraph.co.uk to look in public_html/polargraph_newsite if I want to test something new out.  But it’s not as easy to redirect visitors to this site (euphy.co.uk), because the main domain can’t be treated that way, it seems.  I don’t pretend to understand why.

So I have this site running in a subdirectory (public_html/ev3), and use following mod_rewrite rules in the .htaccess file to rewrite the incoming urls:

Options +FollowSymlinks
RewriteEngine on
IndexIgnore *

RewriteCond %{HTTP_HOST} ^(www.)?euphy.co.uk$
RewriteCond %{REQUEST_URI} !^/ev3/
RewriteRule ^(.*)$ /ev3/$1
RewriteCond %{HTTP_HOST} ^(www.)?euphy.co.uk$
RewriteRule ^(/)?$ ev3/index.php [L]

In this case, because I installed wordpress into euphy.co.uk/ev3/, all of the urls in the site pointed there as the root, instead of to www.euphy.co.uk.  This exasperated me in the past, and every time I’ve done this, because I thought there was some rewriting magic going on.  But it’s dead simple, it’s just the root domain name settings in wordpress itself (admin->settings->general->wordpress address and site address).  DUH.

Leave a Reply

Your email address will not be published. Required fields are marked *