2

My actual url looks like this:

http://mydomain.com/example.php?id=value1&name=value2

Ideal for me would be something like:

http://mydomain.com/example/value2

I dont want to show the items id. I googled for hours but didn`t find anything usefull. I want to pass the id along but dont want to show it in URL. Is something like this possible? Could i maybe rewrite the url somehow after client loaded the page?

If i must send the id then how could i rewrite the name value, accodring to id? So if i type something not related to item with specified id in the name field, on response i sitll get the actual value for name associated to id. So this is what i mean:

  • the actual ulr is: http://mydomain.com/example/123
  • what i type: http://mydomain.com/randomtext/123
  • and i still get the response: http://mydomain.com/example/123

Just like here: http://www.theatlantic.com/magazine/archive/1939/03/what-makes-an-american/309021/ If you change what-makes-an-american to any random text, you still get to the same page. Do they use redirect? Isn`t that harmfull to loadtime?

Wh1T3h4Ck5
  • 8,399
  • 9
  • 59
  • 79

2 Answers2

1

No, its not to harmful for loadtime

<IfModule mod_rewrite.c>
RewriteEngine On
# /var1/value2.html to /example.php?id=value1&name=value2
RewriteRule ^([^/]+)/([^\.]+)\.html$ /example.php?id=$1&name=$2
</IfModule>

The answer was here.

Community
  • 1
  • 1
faq
  • 2,965
  • 5
  • 27
  • 35
0

Save this as your .htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond $1 !^index\.php
RewriteRule ^(.*)/$ index.php/$1 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [QSA,L]

Then, you can use the REQUEST_URI server variable to retrieve the URL components.

For instance, with http://mydomain.com/example/value2:

$var = split('/', $_SERVER['REQUEST_URI']);

$var becomes array('example', 'value2');
Daniel Li
  • 14,976
  • 6
  • 43
  • 60
  • I dont think thats what i need. Currently I`m using this `RewriteRule ^destination/([0-9]+)/([-a-z]*)$ details.php?name=$2&id=$1 [L]` , but if i write some random thext for $2 ( name value ) it still goes to page with passed is but with wrong text. I want at least to rewrite the name part of the url to the correct one. I hope you undestand. – Kobulniczky Csongor Sep 22 '12 at 17:14