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 need to do the following URL rewriting:

/.*  -> /test/$1

How can I set it up with mod_rewrite?

This is my full config:

<VirtualHost *:80>
  ServerName main.domain
  ServerAlias supplementary.domain
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^supplementary\.domain$
  RewriteRule ^(.*)$ /supplementary$1 [NS]  <-- doesn't work
  <Location "/supplementary">
    .. custom config ..
share|improve this question
You're missing the leading slash in the rewrite rule. – matthew Mar 13 '11 at 0:37

Try the following mod_rewrite config

RewriteEngine on
RewriteCond %{REQUEST_URI} ! ^/test/
RewriteRule ^/(.*)$ /test/$1


RewriteEngine on
RewriteRule ^/(.*)$ /test/$1 [NS]

share|improve this answer
In this case /test/ won't be forwarded, right? It's not a correct approach, since I still want /test/ to be forwarded to /test/test/ – yegor256 Mar 12 '11 at 9:05
Ok, then try to append [NS]to the RewriteURL and leave away the RewriteCond. I’ll edit the example above. – Adrian Heine Mar 12 '11 at 9:11
see the updated question. Currently it doesn't work – yegor256 Mar 12 '11 at 9:43
Could you provide some more information? Where exactly to you insert the rules? You could add a rewrite log as well to debug whether the rules are applied at all. – Adrian Heine Mar 12 '11 at 9:43

If neither of Adrian Lang's examples work you could try something like this. The rewrite conditions will prevent it from doing further rewrites if the file exists.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /test/$1
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.