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 www.mysite.com will go to www.mysite.com/sub/

but www.mysite.com/sub/page will go to www.mysite.com/page;

but, I need to keep www.mysite.com/sub/a_particular_page to point to www.mysite.com/sub/a_particular_page

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!!!

link|improve this question
feedback

1 Answer

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]
link|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} !mysite.com/sub/?q=content/a_particular_page RewriteBase / – ale Sep 14 '10 at 15:52
I have used RewriteCond %{REQUEST_URI} !mysite.com/sub/?q=content/a_particular_page 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
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.