[英]how to make a friendly url in php with .htaccess file using php
I have a problem in sending variables through URL by using .htaccess file. 我在使用.htaccess文件通过URL发送变量时遇到问题。
I have two pages projects.php
and project-view.php
when I send variable from 我有两个页面projects.php
和project-view.php
当我从送变量
projects.php
to project-view.php
it corrupted. projects.php
到project-view.php
它已损坏。
my projects.php
我的projects.php
URL:G-Zip/Projects
project-view.php project-view.php
URL:G-Zip/project-view.php?id=11042
I want URL to be like this project-view/11042 . 我希望URL像这个project-view / 11042 。
htaccess file: htaccess文件:
RewriteEngine On
RewriteRule ^projectview/([0-9]+)/?$ /view_project.php?id=$1 [L,QSA,NC]
what can u do in php code backend 您可以在php代码后端中做什么
What you mean with corrupted
? corrupted
是什么意思?
I think that your problem is with the .htaccess
file rewrite rule: 我认为您的问题出在.htaccess
文件重写规则上:
RewriteRule ^projectview/([0-9]+)/?$ /view_project.php?id=$1 [L,QSA,NC]
I think that you have a error in the regular expression and according to your text, you don't have any view_project.php
file, you have to change to: project-view.php
. 我认为您在正则表达式中存在错误,根据您的文本,您没有任何view_project.php
文件,必须更改为: project-view.php
。
I want URL to be like this project-view/11042. 我希望URL像这个project-view / 11042。
Try with backup your file and change the following line: 尝试备份文件并更改以下行:
RewriteRule ^project-view/(\\d+)*$ ./project-view.php?id=$1
This should treat www.url.com/project-view/11
as www.url.com/project-view.php?id=11
这应将www.url.com/project-view/11
视为www.url.com/project-view.php?id=11
Then in the project-view.php
you will receive a $_GET['id']
and you can work with it. 然后在project-view.php
您将收到一个$_GET['id']
,您可以使用它。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.