-8

I want to make something like:

www.example.com/var1/var2/

where I can take the value of the variables, but it also need to be compatible with GET like:

www.example.com/var1/var2/?feat=1234

How can I do this?

Thanks

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Xriuk
  • 429
  • 5
  • 16
  • http://stackoverflow.com/questions/16388959/url-rewriting-with-php. This link would help – Telvin Nguyen Aug 19 '13 at 09:44
  • The `.htaccess` route in the link above will require the flag `[QSA]` for your example link to work – MDEV Aug 19 '13 at 09:46
  • @Bora Looks like the OP wants only partial re write `?this=1&andthis=2&butnotthis=3` to `/1/2?butnotthis=3` – HMR Aug 19 '13 at 10:06

2 Answers2

2

<?php
$url = $_SERVER['REQUEST_URI'];
$url_splitter = explode('/', $url);
echo '<pre>';
print_r($url_splitter);
?>

Now you can access the variables by taking $url_splitter[0], $url_splitter[1],....

Mohan Raj
  • 447
  • 1
  • 5
  • 18
-2

Check out symfony or codeigniter

The documentation will explain how to do a mod rewrite to get the url you want.

A partial re write can be done in this way (have not tested)

http://forums.devshed.com/apache-development-15/partial-mod-rewrite-454669.html

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?var1=$1&var2=$2 [QSA,L]

That should turn a url like /foo/bar/?var3=baz into /index.php?var1=foo&var2=bar&var3=baz I am not sure it'll work though because I don't know how the regexp in the mod rewrite works.

HMR
  • 37,593
  • 24
  • 91
  • 160
  • A whole framework for URL rewriting?? – MDEV Aug 19 '13 at 09:49
  • @SmokeyPHP `The documentation will explain how to do a mod rewrite to get the url you want.` And yes, I might as well mention the framework as it makes for some interesting reading. – HMR Aug 19 '13 at 10:00