HTML 查询字符串的替代方法


Alternative to HTML query string

我看到一些网站使用链接,例如: www.example.com/r/0000 - 零是帖子、用户等的 ID。

我现在使用的将是 www.example.com/view.php?id=0000 ,它看起来更丑陋。

显示的第一种方法的术语是什么,我将如何实现它以由我的网站上的 PHP 脚本处理?

这些网站使用MVC模式(可能使用LaravelSlim等框架)。

拉维尔路线:

Route::get('proyects/id/{id}', array('as' => 'proyects_id', function($id) {
        /* This code is executed. You can return a view or make other things */
}));

当我访问www.mywebsite.com/proyects/id/3路由运行时;您还可以在控制器中执行如下函数:

Route::get('proyects/id/{id}', array('uses' => 'ProyectsController@makeAnything'));

这样,您就可以在没有该表示法的情况下通过 URL 传递信息。


我建议学习拉拉维尔,它真的很有用。

拉维尔网站: http://laravel.com/

在称为人类友好的URL中。您可以通过配置.htaccess文件来执行此操作。

<IfModule mod_rewrite.c>
RewriteEngine On
# if requested url does not exist redirect it to index.php
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [QSA,L]
</IfModule>

所有请求都将在 index.php 上重定向。然后你需要使用模式路由б,它包含在所有流行的框架中 - Symfony,Laravel,Zend等。但在实施中没什么大不了的。