htaccess的重写,包括文件的每个文件夹中 [英] htaccess rewriting to include file in every folder

查看:245
本文介绍了htaccess的重写,包括文件的每个文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,我可以用htaccess的URL重写功能,看起来像有一个在假设一个文件中的 /公/部分/文件夹时,它实际上是在 /公共

Is there a way I could use htaccess' url rewriting feature to look like there's a file in let's say the /public/some/folder when it's actually in /public.

例如我的index.php在根文件夹,我希望它是这样的,当我访问的index.php那么它也可能表现为它的所有文件夹和子文件夹太

For example I have index.php in root folder and I want it to be like that when I access index.php then it could also behave as its in all the folders and subfolders too

在我执行的index.php那么它也将在所有文件夹和子文件夹也执行

When I execute index.php then it will also execute in all folders and subfolders too

更新

请了解以下

的index.php是根,我有不同的文件夹中的根,以及 所以当我通过浏览器访问的index.php那么它也将在其他文件夹执行

index.php is in root and I have different folders in root as well so when I access the index.php through browser then it will also execute in other folders

http://example.com/index.php 也将像它的子文件夹太

http://example.com/index.php will also behave as if its in sub folder too

http://example.com/folder1/index.php

http://example.com/folder2/index.php

http://example.com/folder3/index.php

的index.php 是不是在这些文件夹,但它必须在这些文件夹也同时执行

index.php is not in these folders but it must execute in these folders too at the same time

我认为它不是很难理解通过这个example.please答案相应

I think its not difficult to understand through this example.please answer accordingly

推荐答案

我不知道我理解正确。但是,任何方式,你可以尝试在你的.htaccess类似的东西

I'm not sure that I understand you correctly. But any way you can try something like that in your .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

所以之后一切都会到index.php与$ _GET [页码]参数。因此,例如www.mydomen.com/try/to/get/this会去我们的index.php,我们将有我们的$ _GET [页码] =尝试/到/得/此。如果要使用爆炸该字符串你可以写你想为你URL的规则。喜欢的东西你自己的网址经理:)

So after it everything will go to index.php with $_GET[page] parameter. So for example www.mydomen.com/try/to/get/this will go to our index.php where we will have our $_GET[page]="try/to/get/this". If you will use explode for this string you can write any rules you want for you url. Something like your own URL manager :)

例如:

把你的index.php在根文件夹,也的.htaccess 在您的index.php:

put your index.php in the root folder and also .htaccess in your index.php:

$urlArray = explode("/",$_GET['page']);
switch($urlArray[0]){
  case "try":
     include($_SERVER[DOCUMENT_ROOT]."/path/to/folder/what/you/need/my.php");
     break;
  case "another_url":
     include($_SERVER[DOCUMENT_ROOT]."/another/path/to/folder/what/you/need/my_another.php");
     break;
}

希望这是你所需要的。

Hope it is what you needed.

这篇关于htaccess的重写,包括文件的每个文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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