Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

.htaccess - htaccess RewriteRule redirecting to parent directory?

I cant understand how to redirect to the parent directory in this case: I have a root directory with .htaccess file, where rewriteEngine is on. In this directory I have a file rootFile.php. Also, in this directory I have a directory "forum", with another .htaccess file in it.

When there is request to "forum.mySite.com/rootFile.php", I need to redirect it to "mySite.com/rootFile.php" which means I need to redirect request to the parent directory.

/forum/.htaccess:

RewriteEngine on

RewriteBase /forum/

RewriteRule ^sitemap                    /forum/map.php                [L]
...

I tried to:

RewriteEngine on

RewriteBase /forum/

RewriteRule ^rootFileName                   ../rootFile.php            [L]
# or so RewriteRule ^rootFileName           /rootFile.php              [L]
# or so RewriteRule ^rootFileName           rootFile.php               [L]

RewriteRule ^sitemap                    /forum/map.php             [L]

Also tried this one:

RewriteEngine on

RewriteBase /

RewriteRule ^rootFileName                   ../rootFile.php            [L]
# or so RewriteRule ^rootFileName           /rootFile.php             [L]
# or so RewriteRule ^rootFileName           rootFile.php              [L]

RewriteBase /forum/

RewriteRule ^sitemap                    /forum/map.php             [L]

And it always redirect from /forum/rootFileName to /forum/rootFile, but never to /rootFile.

Where is my mistake?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't rewrite to outside the document-root. This is a security thing.

You could just create a rootFile.php that only contains <?php include('../rootfile.php'); ?>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...