Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 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 Answer

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'); ?>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...