gpt4 book ai didi

php - 使用 PHP 和 Apache 路由 URL 路径

转载 作者:可可西里 更新时间:2023-11-01 00:09:55 25 4
gpt4 key购买 nike

我正在尝试为我的网站创建一个漂亮的 url 结构。

只有当 url 的样式为 ?something=value 时,我的路由器类才会工作。

我如何获得它才能像这样工作:

/something/value

在我的 .htaccess 中我有:

Options FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|txt|gif|jpg|png)$ index.php?$1 [L,QSA]

在我的路由器类中,我正在制作:

class init {

function __construct()
{

$URL = substr($_SERVER['REQUEST_URI'], 19) ;
$URLElements = explode('/', $URL) ; // Adjust if needed.

$class = $URLElements[0] ;
$method = $URLElements[1] ;

if(($t = substr_count($URL, '/')) > 1)
{
for($i=2;$i<$t+1;$i++) {
echo $URLElements[$i].'<br />';
}
}
}

感谢 Jason,我的 .htaccess 现在只是:

FallbackResource /t2013/public_html/index.php

最佳答案

快速处理Front-end Controllers的方法对于 Apache,使用 FallbackResource并用 PHP 解析 URL。

FallbackResource /index.php

关于php - 使用 PHP 和 Apache 路由 URL 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com