繁体   English   中英

htaccess数组的文件路径

[英]htaccess file path to array

我对htaccess的工作不多,通常使用已经完成的框架。 我已经检查了多个站点以学习htaccess,但它们都很难掌握。 我尝试了一些乱码,然后在stackoverflow上的其他地方查找,我发现其中一些执行第一个目录或一组有限的目录,但没有其他目录,而且我没有运气。

我正在寻找的是这样做...

用户在其地址栏中输入(或浏览)以下内容之一...

example.com
example.com/foo/bar/
example.com/some/really/long/set/of/directories/.../that/seems/to/go/on/forever

并最终将所有重定向处理

example.com/index.php

充满了路径的数组,例如

// in index.php
print_r (myarray);
// printing something like...
// []
// or
// ["foo", "bar"]
// or
// ["some", "really", "long", "set", "of", "directories", ... , "that", "seems", "to", "go", "on", "forever"]
// respectively.

您可能会捕获主机部分之后的所有内容,并将其附加到.htaccessdir变量中:

RewriteRule ^example.com(.*) http://example.com?dir=$1 [QSA,L]

要么:

RewriteRule ^%{HTTP_HOST}(.*) http://%{HTTP_HOST}?dir=$1 [QSA,L]

然后在您的PHP中,您可以根据需要使用$_GET['dir']

$array = explode('/', $_GET['dir']);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM