views:

37

answers:

2

Hello, I have a server. (Apache).

On this server there is a subdirectory (subdir1). In this subdirectory, I have an .htaccess file. How can I set up this .htaccess file to redirect me from the directory it is in (regardless of what the directory is called) to a specific subdirectory?

Redirect {current .htaccess directory} {current .htaccess direcotry}/subdir2/subdir3

Or something like that?

Thanks in advance!

A: 

Just use RedirectPermanent.

RedirectPermanent /cur_dirr/ /curr_dirr/subdir2/subdir3

Regards

Sacx
Well, then I am redirected to /cur_dirr/subdir2/subdir3subdir2/subdir3subdir2/subdir3... and I get a browser error of having been redirected too often. Plus, this is not regardless of the directory name.
arik-so
+1  A: 

Are you sure you want a redirect? If you redirect from /subdir1 to /subdir1/subdir2, you are still inside /subdir1, so quite clearly you'll get another redirect to /subdir1/subdir2/subdir2, then /subdir1/subdir2/subdir2/subdir2, and so on until the browser gives up. (As you say in your comment to Sacx's answer.)

If you want to redirect into /subdir1/subdir2, you'll have to exclude subdir2 from matching the redirect, for example something like:

RedirectMatch permanent /subdir1(?!/subdir2)(.*)$ http://www.example.com/subdir1/subdir2$1

this is pretty ugly though. It's unusual to want to do a redirect from a directory to a subdirectory of itself. Are you sure you really want a redirect? If you just want to make files physically located under /subdir1/subdir2/file look visible as /subdir1/file, I think what you'd want would really be an Alias:

Alias /subdir1 /home/wwwuser/examplesite/htdocs/subdir1/subdir2
bobince