htaccess的重写规则重定向到父目录? [英] htaccess RewriteRule redirecting to parent directory?

查看:449
本文介绍了htaccess的重写规则重定向到父目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解如何重定向到在这种情况下,父目录: 我有.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'); ?>

这篇关于htaccess的重写规则重定向到父目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆