0

I the want user to visit www.domain.com/item/ABC123


As you can see here ABC123 should be the input parameter

like this www.domain.com/item/?Id=ABC123

Under /item/ there is an index.php file, that will take an Id input parameter, how do I pass the input parameter value from www.domain.com/item/ABC123 to the id input parameter of the index.php file?

001
  • 62,807
  • 94
  • 230
  • 350
  • 1
    possible duplicate of [Apache Mod-Rewrite Primers?](http://stackoverflow.com/questions/122097/apache-mod-rewrite-primers) and probably 100 more threads on mod_rewrite. – j08691 Apr 02 '12 at 03:30
  • 1
    possible duplicate of [How do I use mod_rewrite to change the path and filename of a URL](http://stackoverflow.com/questions/105308/how-do-i-use-mod-rewrite-to-change-the-path-and-filename-of-a-url) – outis Apr 02 '12 at 03:35

4 Answers4

1

using .htaccess file

add rewrite rule:

RewriteRule ^/item/([a-zA-Z0-9-]*)$ /item/index.php?id=$1 [QSA,L,E]
aifarfa
  • 3,939
  • 2
  • 23
  • 35
0

use mod_rewrite

E.g. http://wettone.com/code/clean-urls

zad
  • 3,355
  • 2
  • 24
  • 25
0

You'll need url rewriting. Basicaly, you'll have an .htaccess with a rewrite rule which will transforms your URL. For instance, www.domain.com/item/some/things/ABC123 into www.domain.com/item/index.php?queryString=some/things/ABC123 and your PHP will do the rest.

user978548
  • 711
  • 2
  • 7
  • 12
0

Something similar to this should work:

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php

index.php

$uri = preg_replace("#(/+)#","/",$_SERVER["REQUEST_URI"]);
$uri = array_shift(explode("/",$uri));

now, $uri is an array of each portion of the URI. so /a/b/c becomes:

array(
    0 => "a",
    1 => "b",
    2 => "c",
)
Navarr
  • 3,703
  • 7
  • 33
  • 57
  • Note, this is a general solution with untested code to enable quick and painless uri routing in a PHP application. – Navarr Apr 02 '12 at 03:35