如何使用htaccess的文件重写URL在PHP。什么样的变化在PHP code [英] How To Rewrite URL in php using htaccess file. what change in php code

查看:168
本文介绍了如何使用htaccess的文件重写URL在PHP。什么样的变化在PHP code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的.htaccess文件。即时搜索净,但即时通讯不能够改变,在PHP重写URL ... 例如

I'm new in .htaccess file. i m searching on net but i m not able to change and rewrite URL in PHP... E.G

显示URL如:

本地主机/网络/网站/ view_project.php?VP = 14

localhost/web/site/view_project.php?vp=14

我要展示我的URL如

本地主机/网络/网站/项目/ 14 /

localhost/web/site/project/14/

在PHP中I M使用code

In php i m use this code

href="view_project.php?vp=<?php echo $c_id>" echo $c_project_title

在.htaccess文件中我使用

In .htaccess file I'm using

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/?$ /view_project.php?vp=1& [L,R]

现在请告诉什么需要PHP code和的.htaccess文件来改变......我完全在这个新的。

Now please tell what need to change in PHP Code and HTACCESS file... I'm totally new in this.

推荐答案

更​​改你的PHP code到这一点:

Change your PHP code to this:

href="project/<?php echo $c_id>" echo $c_project_title

然后通过的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在的.htaccess DOCUMENT_ROOT 目录下:

And then enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^project/([0-9]+)/?$ /view_project.php?vp=$1 [L,QSA,NC]

这篇关于如何使用htaccess的文件重写URL在PHP。什么样的变化在PHP code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆