1

I'm almost done writing the .htaccess file to redirect some URLs to a new domain.

One final thing: I have URLs with this structure:

http://www.domain.be/?s=searchterm

How do I capture them?

RewriteRule ^\?s=(.*)$       http://newsubdomain.domain.be/?s=$1    [NC,L]

Any ideas?

Wolfr
  • 23
  • 3

2 Answers2

1

RewriteRule only matches the path, not the query string. You need to add a RewriteCond for that.

Note the percent back-reference %1 which inserts the search term captured in the RewriteCond. The slash in the RewriteRule is in effect a no-op, since we don't care about anything in the URL path.

RewriteCond %{QUERY_STRING} ^s=(.*) [NC]
RewriteRule / http://newsubdomain.domain.be?s=%1 [R,L]
0

You'll need to start your regex with a / - so in your case:-

RewriteRule ^/\?s=(.*)$
Andy Smith
  • 1,828
  • 14
  • 15
  • No. As h0ward already mentioned in his answer, the pattern in `RewriteRule` does not match the query string. See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule in the box "What is matched?" – joschi Jun 13 '10 at 05:50