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

The same Apache rewrite rule works (match) in VHost but not in ".htaccess" file:

<VirtualHost *:80>
DocumentRoot /test

RewriteEngine On
RewriteRule ^/test.html$ /test2.html
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

<Directory "/">
AllowOverride All


Rewrite Log: - - [13/May/2013:16:19:31 +0100] [][rid#7fd764ad9758/initial] (2) init rewrite engine with requested uri /test.html - - [13/May/2013:16:19:31 +0100] [][rid#7fd764ad9758/initial] (3) applying pattern '^/test.html$' to uri '/test.html' - - [13/May/2013:16:19:31 +0100] [][rid#7fd764ad9758/initial] (2) rewrite '/test.html' -> '/test2.html' - - [13/May/2013:16:19:31 +0100] [][rid#7fd764ad9758/initial] (2) local path result: /test2.html - - [13/May/2013:16:19:31 +0100] [][rid#7fd764ad9758/initial] (2) prefixed with document_root to /test/test2.html - - [13/May/2013:16:19:31 +0100] [][rid#7fd764ad9758/initial] (1) go-ahead with /test/test2.html [OK]

".htaccess file"

# cat /test/.htaccess 
RewriteEngine On
RewriteRule ^/test.html$ /test2.html

Rewrite Log: - - [13/May/2013:16:22:17 +0100] [][rid#7fd764af0d78/initial] (3) [perdir /test/] strip per-dir prefix: /test/test.html -> test.html - - [13/May/2013:16:22:17 +0100] [][rid#7fd764af0d78/initial] (3) [perdir /test/] applying pattern '^/test.html$' to uri 'test.html' - - [13/May/2013:16:22:17 +0100] [][rid#7fd764af0d78/initial] (1) [perdir /test/] pass through /test/test.html
share|improve this question
up vote 3 down vote accepted

According the second log, it's looking for "^/test.html$" in "test.html" URL. Cannot match it because of forward slash in pattern. Try

RewriteRule ^test.html$ /test2.html

instead of

RewriteRule ^/test.html$ /test2.html

in your .htaccess file.

share|improve this answer

Add this above the RewriteRule in your .htaccess:

RewriteCond %{HTTP_HOST} ^(www.)?/test/test.html$

Change the path to suit your environment.

share|improve this answer

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.