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.

Possible Duplicate:
Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

I have a folder ~/Branches/ that is accessible via apache2 at localhost/~me/. Now I have localhost/~me/branches_index/web/index.php that I would like to make available at localhost/~me/branches_index/

So how can I redirect from /~me/branches_index/ to /~me/branches_index/web/ from the /Branches/branches_index/ folder?


I tried, but I did not succeed.

Endless loop:

Redirect /~me/branches_index/ /~me/branches_index/web/

Put /web/ at the front:

Redirect / /web/
share|improve this question

marked as duplicate by SvW, MadHatter, Ward, MDMarra, voretaq7 Mar 3 '12 at 7:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Your question isn't really a duplicate of the mod_rewrite question, but you'll find more details on how to do what you want over there :) –  voretaq7 Mar 3 '12 at 7:03

2 Answers 2

The redirect you're attempting is failing because
Redirect /~me/branches_index/ /~me/branches_index/web/
will redirect everything from /~me/branches_index/* recursively.

That means /~me/branches_index/what/so/ever
will be redirected to /~me/branches_index/web/what/so/ever thus you end up in an endless cycle.

The solution is to use rewrite in .htaccess file, saved at /~me/branches_index/.
Something like this code should do the work:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^(.*)web/(.*)$
RewriteRule ^(.*)$ /~me/branches_index/web/$1 [NC,L]
share|improve this answer

One way would be to put this in the or .htaccess configuration for /branches_index/

RewriteEngine On
RewriteCond %{REQUEST_URI} !^web/
RewriteRule (.*) web/$1 [QSA,L]
share|improve this answer

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