开发者

URL rewriting from root to parent directory

I need to write a rule to redirect a page to a parent directory in a .htacces file.

For instance, this is my files system :

- a-directory
- another-directory
-- a-file

i've got a virtualhost which is a pointer to "a-directory"

so when i go to http//my-v开发者_开发知识库irtualhost/a-file, i need to go back to the parent directory and open "a-file" in the directory "another-directory".

First at all, is that possible ? Then, how can i write this ?

Thank you!


Out of curiosity, is there a reason you wouldn't just point your virtual host to "another-directory" to begin with, if everything is just redirecting there?

Assuming you can put a .htaccess file above "a-directory", it would just be a matter of doing something like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^a-directory/(.*) another-directory/$1

If for whatever reason the .htaccess file couldn't go there, you'd need something more geared for this kind of task, like mod_alias.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜