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

I try to use the first part of the fqdn as a rewrite target:

http://demo.dev.example.com/something => http://demo.dev.example.com/demo/something

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).dev.example.com [NC]
RewriteRule ^/(.*) http://%1.dev.example.com/%1/$1 [P]

This creates an endless loop. So I need another condition that checks if this request is already rewritten or not:

RewriteCond %{REQUEST_URI} !^/%1

Well this is not working, the documentation says nothing about using backreferences in CondPatterns, most possibly it's not supported.

RewriteCond %{REQUEST_URI} !^/demo

This works perfectly, but isn't dynamic.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Solution/Workaround: reserve one hostname part for internal requests:

RewriteCond %{HTTP_HOST} !^internal.dev.atizo.org [NC]
RewriteCond %{HTTP_HOST} ^([0-9a-z-]+).dev.atizo.org [NC]
RewriteRule ^/(.*) http://internal.dev.atizo.org/%1/$1 [P]
share|improve this answer

If you don't need to process any rules after the rewrite, just add the "L" = "last" option in the square brackets:

RewriteRule ^/(.*) http://%1.dev.example.com/%1/$1 [P,L]

share|improve this answer
2  
Won't help. This is still doing endless loops. RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).dev.atizo.org [NC] RewriteRule ^/(.*) http://%1.dev.atizo.org/%1/$1 [P,L] –  turingmachine Aug 11 '10 at 9:21

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.