Changing Directory Location Using .htaccess

by admin on January 13, 2010

I’ve been playing around with Magento and WordPress recently (more specifically trying to integrate both in design and navigation) and decided to move the installations of WordPress and Magento into seperate directories in a site root using .htaccess

This should work for any dynamic content cms/ecommerce platform (depending on their internal URL structure and customisability), try it out in .htaccess:

Options +FollowSymLinks
RewriteEngine on

#rewrite everything to index.php apart from blog pages

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule . /shop/index.php [L]

DirectoryIndex shop/index.php

This basically rewrites all URLs that aren’t physical files or directories to ‘shop/index.php’, with the exception of any URIs starting with ‘/blog/’.

The last statement tells the root to serve ‘shop/index.php’ (this can cause duplicate content between root and ‘shop/index.php’ so add a RewriteRule to prevent it).

Why Would I Want to Do This?

My only reason for doing so was to move seperate installations into subfolders (while serving /shop/index.php at the root) – just helps keep everything tidy and segmented in the server root directory.

Leave a Comment