我试图根据在url上传递的参数显示特定项目的详细信息。但我不希望页面和变量显示在网址上,并且希望仅使用参数来使用$_GET['id']
进行进一步的功能操作。我的代码有点像这样....
<a href="details.php?id=1">Get Detail</a>
地址栏是:: localhost/project/details.php?id=1456
我可以得到像:: localhost/project/1456
答案 0 :(得分:0)
我假设你正在使用Apache。因此,启用mod-rewrite并将.htaccess
文件放入您的Web根目录。
配置frendly linka你需要像:
RewriteEngine On
RewriteRule ^/?(.*)$ details.php?id=$1 [NC,L]
--EMPTY LINE OR FILE WILL FAIL--
此文件应驻留在项目目录中 空行很重要!
答案 1 :(得分:0)
在项目文件夹中创建.htaccess文件,并将这些行复制到.htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/project/([0-9]+)$
RewriteRule ^(.*)$ /project/your_file_to_run.php?id=$1 [L]
在您的php文件 your_file_to_run.php 中,您可以使用$ _GET ['id']来获取id的值
答案 2 :(得分:0)
将它放在项目目录中
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\d]+)$ details.php?id=$1