htaccess的重写规则重定向到父目录?重写、重定向、规则、目录

2023-09-02 09:39:09 作者:持刀战情场

我无法理解如何重定向到在这种情况下,父目录: 我有.htaccess文件,其中RewriteEngine叙述是一个根目录。在这个目录中我有一个文件rootFile.php。 此外,该目录中我有一个目录下的论坛,在它的另一个.htaccess文件。

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.

当有请求forum.mySite.com/rootFile.php,我需要重定向到mySite.com/rootFile.php,这意味着我需要重定向请求上一级目录。

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:

/forum/.htaccess:

RewriteEngine on

RewriteBase /forum/

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

我想:

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]

和它总是从/论坛/ rootFileName重定向到/论坛/的rootfile,但从来没有到/的rootfile。

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

在哪里是我的错?

推荐答案

您不能改写到文档根目录之外。这是一个安全的事情。

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

您可以只创建一个rootFile.php仅包含< PHP的包括:('../ rootfile.php'); ?>

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

 
精彩推荐
图片推荐