繁体   English   中英

PHP Front Controller使用HTACCESS文件获取目录

[英]PHP Front Controller to get the Contents using HTACCESS file

我试图获取漂亮的URL。 我添加了一个获取URL的前端控制器,这是HTACCESS文件和控制器的代码

RewriteEngine on
RewriteCond $1 !^(index\.php|search\.php|lib|css|ajax|includes|js|classes|parts|pages|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

控制器文件

$URL = $_SERVER["REQUEST_URI"];

$all_parts = explode("/", $URL);

我的网址就像

www.example.com/pretty-ulr/10.html

我得到的页面ID是page.php?p_id=10 (这是一个简单的示例。我使用的是更复杂的示例。)

但是我不确定如何在这里获取内容或重定向t0 page.php?p_id = 10以显示此页面的内容。 当我使用header()重定向时,它没有到达那里

.htaccess文件中的文件可能很小,但我不确定。 任何想法请如何获取页面内容。

我建议在.htaccess使用类似这样的内容:

RedirectMatch ^/$ /index.php

然后在php中执行以下操作:

$url=parse_url($_SERVER['REQUEST_URI']);
$urls=explode('/',rawurldecode(trim($url["path"],'/')));
new Controller($urls);

Controller类将解析这些URL并获得正确的视图。

暂无
暂无

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

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