的.htaccess文件夹制作充当根? [英] .htaccess make folder act as root?

查看:171
本文介绍了的.htaccess文件夹制作充当根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使的.htaccess告诉一个文件夹作为最低水平?我的意思是这样的,说你有一个文件夹,如下所示:

Is there a way to make .htaccess tell a folder to act as the lowest level? What I mean is this, say you have a folder like so:


/about/
/contact/
/css/
/images/
.htaccess
index.php
header.php

如果他们是在 /contact/index.php ,然后如果我有< A HREF =../的index.php >家< / A> 转到主页,它工作一切正常,但如果是实际的主页上,它会尝试去一个目录下

If they are at /contact/index.php, then if I have <a href="../index.php">Home</a> to go to the home page, it works all fine, but if they are on the actual main page, it will try to go a directory lower.

的原因是因为林试图测试在子文件夹的网站。

The reason is because Im trying to test sites in sub-folders.

推荐答案

的直接回答你的问题,答案是的没有的。到时候,的.htaccess被读取后,路径已经被转变为一个目录。

The directly answer your question, the answer is no. By the time, .htaccess is read, the path was already translated to a directory.

如果你想改变的根,你所要做的是在的httpd.conf (或重写根的所有请求到目标目录)。如果你想有几个根(不同的域下),你必须使用虚拟主机(同样,只有在的httpd.conf )。

If you want to change the root, you have to do it in httpd.conf (or rewrite all the requests in the root to the destination directory). If you want to have several roots (under different domains), you have to use virtual hosts (again, only in httpd.conf).

您也可以使您的网站的工作时,它不是在根目录下。

You can also make your site work when it's not in the root directory.

  • 在正确使用相对路径(在/contact/index.php,并在根网页的index.php../index.php)。不是一个很好的选择。
  • 使用绝对路径,但是preFIX他们相对于服务器的根网站的路径。最防呆的方式来做到这一点设定恒定为这,你在所有的脚本包括一个文件。

这篇关于的.htaccess文件夹制作充当根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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