Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to include slashes in url parameter rule? Basically I want to go to Any examples would be appreciated.


share|improve this question
yes you can include it. – Prix Aug 18 '10 at 10:33
up vote 3 down vote accepted

An example of a rewrite rule that could accomplish this is:

RewriteEngine on RewriteRule ^/?(.+)$ ?q=$1

This will capture everything after "" and convert it to the q=x form.

I assume you are using Apache in front of some dynamic server-side program, like Tomcat or PHP, because Apache on its own can't really do anything smart with a URL containing a query string. In this case, you may need to add the [PT] flag to your Rewrite Rule, to ensure that the inbound URL gets rewritten before it is passed along to your dynamic engine. The rule would then look like:

RewriteRule ^/?(.+)$ ?q=$1 [PT]

You should also consider what will happen if your original inbound URL contains a query string of its own. This example rule will not include the inbound query string when it does the rewrite, but you can make it do so with the QSA flag.

share|improve this answer
Sorry, I could not get the formatting to work on the first line of code. Those are supposed to be two separate lines, with "RewriteEngine on" as its own line. – jfrank Aug 18 '10 at 17:28
for the formating, you can end 1st line with [enter] and start next line with 4 spaces. – laurent Aug 18 '10 at 17:46
Thanks, that really helps. – James Canning Aug 18 '10 at 23:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.