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

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

问题描述

在这种情况下,我无法理解如何重定向到父目录:我有一个包含 .htaccess 文件的根目录,其中 rewriteEngine 处于打开状态.在这个目录中,我有一个文件 rootFile.php.此外,在此目录中,我有一个目录forum",其中包含另一个 .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]

也试过这个:

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]

它总是从/forum/rootFileName 重定向到/forum/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.

你可以创建一个只包含 <?php include('../rootfile.php'); 的 rootFile.php;?>

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

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

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