0

People I have been working for days in this and I,m no able to make it work.

I,m trying to do a RewriteRule in my apache server but is not working.

if i use a simple url like this it works perfect.

RewriteEngine On RewriteRule ^(/.php/m/) htp://www.index.php 

but if i use a complex url dont work , something like this:

RewriteEngine On RewriteRule ^(/index.php?option=com_rsform&Itemid=8&lang=en) htp://www.index.php 

does some body know why apache is not understanding this url what i,m missing

index.php?option=com_rsform&Itemid=8&lang=en

5
  • What do you mean by www.index.php? that sounds weird Commented Jan 1, 2010 at 17:37
  • sorry htp://www.index.php is only for the example, the real url will be something like htp://www.mydomain.com/index.php, but my real problem is the first url index.php?option=com_rsform&Itemid=8&lang=en Apache won,t rewrite when i hit that url it seems that it don,t recognize the url or don,t understand it " Commented Jan 1, 2010 at 17:42
  • Have you tried escaping the ? (replace it with \?). It has a special meaning when used in a regular expression, as you're doing. Commented Jan 1, 2010 at 17:46
  • yes i try it like this: index.php\?option=com_rsform&ItemId=8&lang=en but din,t work Commented Jan 1, 2010 at 17:54
  • Actually I don't think the query part is included in the match with a RewriteRule. You can use a RewriteCond expression using %{QUERY_STRING} though. Commented Jan 1, 2010 at 17:58

1 Answer 1

4

The query part is not included when you match an URL with a RewriteRule, see this part of the docs:

What is matched?

The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string. If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.

As suggested by the docs, you can use a RewriteCond expression to match on %{QUERY_STRING}:

RewriteCond %{QUERY_STRING} ^option=com_rsform&Itemid=8&lang=en$ RewriteRule ^index.php$ http://www.index.php 

Note that this only works when the query string is exactly the one you're matching. An equivalent query string in which the order of the arguments is changed, f.i. option=com_rsform&lang=en&Itemid=8, will not be matched. So in this case, I think you'd be better to send all requests to your PHP script, and have that look at $_GET and decide whether to forward or not.

You must log in to answer this question.