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 am desperately looking for some help with apache rewrite.

I have 2 websites; one in root (/) and the other in a subdirectory (/sub)

the two site are nearly identical apart from the home page. how can I use the home page of the one in the sub directory for the root site and whenever a user click on any other page in the subdirectory ( a part from one! ) get rid of the /sub/ bit and send them to the site on the root?

I am using drupal , so to set the homepage for the site in the root to point to the one in the subdirectory should be easy; but the problem is that I want to set a rule in the subdirectory to send all the pages from the subdirectory site to be redirected to the "twin" pages in the root site;

so for example will go to

but will go to;

but, I need to keep to point to

so a part from the home page and the a_particular_page all pages from the subdirectory has to point to the root site;

hope this is not too confusing.

any help is greatly appreciated and thank you in advance!!!

share|improve this question

I've not checked if this works, but something along these lines?

RewriteRule ^/$ /sub/ [R=301]
RewriteRule ^/sub/a_particular_page - [L]
RewriteRule ^/sub/(.+) /$1 [R=301]
share|improve this answer
thank you, if I add this to the .htaccess do I have to change something with regards to the trailing slashes? – ale Sep 14 '10 at 10:02
Shouldn't do. Give it a try and report back if anything goes wrong. – J.Carroll Sep 14 '10 at 11:30
hi, thanks! I have used RewriteCond %{REQUEST_URI} ! RewriteBase / – ale Sep 14 '10 at 15:52
I have used RewriteCond %{REQUEST_URI} ! RewriteBase / and it does what I need – ale Apr 23 '11 at 2:24
ale, maybe you could answer your own question to help other people getting better at writing Apache rewrite rules ;) – Olivier Pons Oct 7 '11 at 14:27

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.