0

I got this url

/localhost/andalucia/productdetails.php?value=20

I want to change it to

/localhost/andalucia/productdetails/20

how do you do this and how will you get the value 20 in the handler page?

should I change the coding or I just add an ht access file?

If it is adding a ht access file what code should be in it?

How if I have more pages like:

/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus

Will they be affected automatically too?
ok i tried to use

RewriteRule ^productdetails/([0-9]+)$ productdetails.php?value=$1 [L,QSA]

but now the problem is all my pictures is gone in the html and i cant open the other page like

/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus

i need a htaccess code that can open all of these

/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
/localhost/andalucia/productdetails/20

pls helpp someone

Joshua Frederic
  • 129
  • 1
  • 2
  • 7
  • You can do this using htaccess. Google for rewrite rules – strauberry Mar 09 '14 at 09:52
  • possible duplicate of [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – ops Mar 09 '14 at 09:53
  • Check this duplicate for your question.. http://stackoverflow.com/questions/1231067/htaccess-rewrite-for-query-string – Bangash Mar 09 '14 at 09:55

1 Answers1

0

With the apache extension mod_rewrite it is really easy to transform your pretty URLs into the URLs needed by your script. This .htaccess example which you place in your web root should get you going:

RewriteEngine On

RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [L]

This example will only rewrite andalucia/productdetails/NNNN... format URLs, all other URLs won't be affected. If you need to pass other query parameters, like /andalucia/productdetails/20?sort=asc you need to pass the QSA flag (query string append) to the rewrite rule:

RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [QSA,L]

The L flag will prohibit the evaluation of next rules. Just look up the mod_rewrite documentation for a in-depth discussion!

Oliver
  • 785
  • 1
  • 7
  • 14