问题
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
Show URL Like :
localhost/web/site/view_project.php?vp=14
I want show my URL like
localhost/web/site/project/14/
In php i m use this code
href="view_project.php?vp=<?php echo $c_id>" echo $c_project_title
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]
Now please tell what need to change in PHP Code and HTACCESS file... I'm totally new in this.
回答1:
Change your PHP code to this:
href="project/<?php echo $c_id>" echo $c_project_title
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]
回答2:
You need to use $1 instead of 1 as you have it now, for more see here: https://serverfault.com/questions/389684/how-can-i-store-request-uri-in-a-variable-manipulate-it-and-then-use-it-in
来源:https://stackoverflow.com/questions/13680295/how-to-rewrite-url-in-php-using-htaccess-file-what-change-in-php-code