Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm in the process of migrating a site across from Wordpress to Octopress - but have managed to completely screw up the mod_rewrite settings in the process.

Currently, all the URLs are in the format

Once ported across to Octopress, they are now in the format:

There are also some top-level pages which are all variations of

and are now

I've got as far as

RewriteRule ^(.+)\.php $1

which seems to work nicely - but as soon as I include a 301 redirect:

RewriteRule ^(.+)\.php $1 [R=301]

the rewrite rule now includes the full file system path - so:

Can anyone point out where I'm going wrong here?


The RewriteRule is in the <Directory> block:

<Directory />
 ReWriteEngine On
 RewriteRule ^(.+)\.php $1
 Options FollowSymLinks
 AllowOverride All
share|improve this question
Include all your rewrite rules and the context they are in (.htaccess file, vhost, global, <Directory /> block, etc.), they can all matter. – Ladadadada Feb 25 '13 at 19:54
up vote 2 down vote accepted

The regex is matching on the filesystem path rather than the URL, which happens in Directory and htaccess context. in VirtualHost context it matches the URL, as detailed in the Apache HTTPD 2.2 documentation for RewriteRule:

What is matched?

In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). In Directory and htaccess context, the Pattern will initially be matched against the > filesystem path, after removing the prefix that lead the server to the current RewriteRule (e.g. "app1/index.html" or "index.html" depending on where the directives are defined). If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.


share|improve this answer
Moving the ReWriteRule out of the <Directory/> block and into the main <VirtualHost> block works a charm. Simple when you know how :-) – TimD Feb 26 '13 at 11:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.