如何使用 $_GET['ID'] 避免 ?id=1 与 /myid 代替

How to use $_GET['ID'] avoiding ?id=1 with /myid instead

我正在尝试找到一种方法,使用 $_GET[''].

使页面可由纯 URL 访问

但不是下面的请求 URL :

http://mywebsite.com/product.php?=1

我要:

http://mywebsite.com/product/1

谢谢你,祝你有愉快的一天。

您需要在网络服务器上启用 PHP - URL-路由器和 mod_rewrite。

如果您没有那么多经验,可以使用 PHP 框架,许多框架确实集成了 Good Routing。

看一些 tutroium 示例:http://blogs.shephertz.com/2014/05/21/how-to-implement-url-routing-in-php/

您应该在 php 中使用 Friendly url 来创建规范 url

您可以使用这种方法:

how-to-create-dynamic-friendly-urls-using-php

how-to-create-friendly-url-in-php

please search friendly url in php

这可以通过 url 重写来实现。听起来您想实现许多 PHP 框架所做的事情。

 for example http://codeigniter.com/user_guide/general/urls.html

在根目录下创建一个 htaccess 文件并在其中写入此代码

RewriteEngine On
RewriteRule ^/product.php?id=([0-9]+)$ /product/

有关 htaccess 的更多详细信息

如果您在本地主机上检查它,请确保在编写此代码后重新启动服务器

RewriteEngine On RewriteRule ^([^/]+)/([^/]+)$ index.php?=

The more number of arguments you enter here that you can access through url

  • $1=$2
  • $1=$2&$3=$4
  • $1=$2&$3=$4&$4=$5

Your answer is given here.