PHP和Apache路由URL路径

编程入门 行业动态 更新时间:2024-10-04 15:28:58
本文介绍了PHP和Apache路由URL路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个漂亮的URL结构为我的网站。

我的路由器类只会工作,如果URL中的风格?东西=价值。

我如何得到它,所以它会像:

/事/值

在我的.htaccess我有:

有FollowSymLinks RewriteEngine叙述上 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 重写规则\(JS | TXT | GIF | JPG | PNG)!?$ index.php文件$ 1 [L,QSA]

和我的路由器类我做:

类的init {     功能__construct()     {     $ URL = SUBSTR($ _ SERVER ['REQUEST_URI'],19);     $ URLElements =爆炸('/',$网址); //如果需要进行调整。     $类= $ URLElements [0];     $方法= $ URLElements [1];     如果(($吨= substr_count($网址,'/'))大于1)     {         为($ i = 2; $ I< $ T + 1; $ I ++){             回声$ URLElements [$ i]。'< BR />';         }     }     }

}

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

FallbackResource /t2013/public_html/index.php

解决方案

对于一个快速的方法来处理正投端控制器的与Apache,使用 FallbackResource ,并用PHP解析URL。

FallbackResource的index.php

I am trying to create a nice url structure for my site.

My router class will only work if the url is in the style of ?something=value.

How do I get it so it will work like:

/something/value

In my .htaccess I have:

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

And in my router class I'm making:

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 />'; } } }

}

Thanks to Jason, my .htaccess is now just:

FallbackResource /t2013/public_html/index.php

解决方案

For a quick way to handle Front-end Controllers with Apache, use FallbackResource and parse the URL with PHP.

FallbackResource /index.php

更多推荐

PHP和Apache路由URL路径

本文发布于:2023-11-02 06:36:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   路径   PHP   Apache   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!