2

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.

acre
  • 283
  • 2
  • 4
  • 6

2 Answers2

2

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Hi.. After This code Showing ERROR on this page.. Not Found The requested URL /v_project.php was not found on this server. – acre Dec 03 '12 at 14:34
  • @acre: Does `view_project.php` even exist under `$DOCUMENT_ROOT` ? – anubhava Dec 03 '12 at 14:54
  • Yes but i want change like ( domain.com/project/14 ) – acre Dec 04 '12 at 12:27
  • I understand that but since you commented that `equested URL /v_project.php was not found on this server` that's why I want to make sure first if target URL: `http://domain.com/view_project.php?vp=14` is serving your page or not. – anubhava Dec 04 '12 at 14:54
  • i have a problem in localhost. online this file working. bt local host not... [ ] – acre Jan 02 '13 at 07:08
  • You have to make sure to enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory on your localhost. – anubhava Jan 02 '13 at 09:33
  • @acre: This is more than 6 months old Q&A. Request you to pls post a new question explaining your problem and I will attend to it. – anubhava Jun 18 '13 at 07:57
  • [http://stackoverflow.com/questions/17162214/htaccess-not-working-on-localhost-with-xampp?noredirect=1#comment24847587_17162214] – acre Jun 18 '13 at 08:29
  • Thanks I will attend that Q&A. – anubhava Jun 18 '13 at 08:38
-1

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

Community
  • 1
  • 1
Maarten
  • 4,643
  • 7
  • 37
  • 51