0

I'm trying to rewrite some URLs, but am not sure how to do what I need. I am having a hard time finding answers online as well, because it's not just a simple re-write, and I don't know the term to search for.

So I could use some help trying to do this, and would like to know if there is a term that is used for this type of thing.

Basically I want to turn this:

http://www.domain.com/search.php?search_type=news&searchterms=2012-04-23

into this

http://www.domain.com/search/news/2012-04-23

But have the search.php script still work the same and get the variables that it needs.

anubhava
  • 761,203
  • 64
  • 569
  • 643
Sherwin Flight
  • 2,345
  • 7
  • 34
  • 54
  • 2
    See the [mod-rewrite](http://stackoverflow.com/questions/tagged/url-rewriting) tag and [tag-wiki](http://stackoverflow.com/tags/mod-rewrite/info); specifically [example 6](http://stackoverflow.com/questions/3655893/rewriting-an-arbitrary-number-of-path-segments-to-query-parameters#3683855) – mario Apr 26 '12 at 19:08
  • It's easy. Just as @mario says. – Shiplu Mokaddim Apr 26 '12 at 19:11

3 Answers3

2

Try this:

RewriteEngine on
RewriteRule ^search/([^/]+)/([^/]+)$ /search.php?search_type=$1&searchterms=$2 [L,QSA]

The [^/]+ matches a sequence of non-slash characters. The QSA option allows URLs like /search/foo/bar?baz=1 to also work.

Cal
  • 7,067
  • 25
  • 28
0

If you're looking for a term to search on, try "ModRewrite" or "Rewrite Rules".

I won't give the exact answer, but here's a random similar rule I've got lying around that might help you figure things out:

RewriteRule ^(.*/)help/([0-9]*?)/(.*)(/?)$ /help.php?category=$2 [QSA,L]
orourkek
  • 2,091
  • 15
  • 22
0

Here you have am amazing guide with lots of examples: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

However, I don't think is a good idea to rewrite the query string of an url.

Marco Panichi
  • 1,068
  • 1
  • 18
  • 31