Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ..
  </Location>
</VirtualHost>
share|improve this question
    
You're missing the leading slash in the rewrite rule. –  matthew Mar 13 '11 at 0:37
add comment

2 Answers

Try the following mod_rewrite config

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

Update:

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 Lang 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 Lang Mar 12 '11 at 9:43
add comment

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
add comment

Your Answer

 
discard

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.