将网址更改为更短[重复]

This question already has an answer here:

I have a URL

http://example.com/test/search.php?id=SearchWord

And i want to change this into

http://example.com/test/SearchWord

Now i tried somethings with .htaccess but i couldn't get it work because i need to $_GET['id'].

I have a if function that checks on $_GET['id'].

How do i do this with the new short URL and how to shorten the URL ?

</div>

Try this ...

RewriteEngine On
RewriteRule ^([^\.]+)$ search.php?id=$1 

You can do this using mod_rewrite in apache.

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

This will let you set a RegEx for the requested URL and forward it to a different URL!

In your .htaccess, give this a try:

RewriteEngine On
RewriteRule ^test/(.*)$ /test/search.php?id=$1 [L]