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.

2
  • 2
    See the mod-rewrite tag and tag-wiki; specifically example 6 Commented Apr 26, 2012 at 19:08
  • It's easy. Just as @mario says. Commented Apr 26, 2012 at 19:11

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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]

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.