2

我想从 htaccess 获取所有数据我知道这是一种愚蠢的问题,但我只是想知道是否可以从 htaccess 规则列表中仅获取用户友好的链接

RewriteRule ^login$ common/login.php [L]
RewriteRule ^forgot-password$ common/forgotpassword.php [L]
RewriteRule ^page/(.*)$ common/page_content.php?pageslug=$1 [L]
RewriteRule ^activate/([a-zA-Z]+)/([0-9]+)/(.*)$ common/activate.php?type=$1&userid=$2&activationcode=$3 [L]
RewriteRule ^forgot-password$ common/forgotpassword.php [L]

我希望这些数据格式为

$data->array(); //is array
$data[0] = login common/login.php 
$data[1] = forgotpassword common/forgotpassword.php or simlar to this 

或者请建议我一些方法来获取我网站中的所有标签及其路径名我想基于 htaccess 动态构建我的站点地图

4

2 回答 2

0

未经测试,但我认为您正在寻找这样的东西:

function rewriteLink($link)
{

    if(preg_match('/^login$/',$link)){return "common/login.php";}
    if(preg_match('/^forgot-password$/',$link)){return "common/forgotpassword.php";}
    if(preg_match('/^page/(.*)$/',$link,$m)){return sprintf("common/page_content.php?pageslug=%s",$m[1]);}
    if(preg_match('/^activate\/([a-zA-Z]+)\/([0-9]+)\/(.*)$/',$link,$m)){return sprintf("common/activate.php?type=%s&userid=%s&activationcode=%s",$m[1],$m[2],$m[3]);}
    return $link;
}

ps您的.htaccess文件包含两个重复的forgotpassword.php重写语句,对于我上面编写的函数,我基于您的htaccess文件但从我的代码逻辑中省略了第二个冗余实例。

于 2012-10-15T12:45:14.787 回答
0
RewriteRule ^(.*?)/(.*?)$ common/$1.php?getValues=$2 [L,NC]

您可以使用此代码,您可以通过此示例制作好的网址:

如果你想去 common/forgot-password.php yoururl.com/forgot-password for go page "aboutus" yoururl.com/page/aboutus 它的意思是:common/page.php?getValues=abouts 你可以用$_GET['getValues'] 或用于多个数据

yoururl.com/activate/type/userid/key meanÇ: common/activate.php?getValues=type/userid/key 并用explode解析:

$datas=explode("/",$_GET['getValues']);
echo "type: $datas[0]
userid: $datas[1]
key: $datas[2]";
于 2012-10-15T11:26:02.640 回答