views:

370

answers:

2

Hi I use .htaccess to perform redirection. Here the line

RedirectMatch permanent .*\?langue=([\w]{2}).*id_([\w]+)=([1-9]+) ***[protocol]***://myserver/rootContext/action?pagename=dir1/dir2/dir3/Redirect&type=$2&id=$3&lang=$1

Here my inital url:

***[protocol]***://localhost/adir/anotherDir/anotherDirAgian/oneMore/apage.php?langue=fr&id_dossier=261

This regular expression is correct, but at least, no redirection is done. With silmple regular expression and simple url it works correctly.

Does somebody can help? Thanks David Hoareau

+1  A: 

RedirectMatch operates against the ‘URL-path’, which does not include any query parameters.

You can match against a query string by using a RewriteCond in mod_rewrite. Although IMO it's a dodgy proposition trying to parse query strings with regex. Any unexpected parameters or ordering could break your regex. Since you aren't matching a particular path, it could also go wrong if any URL in the new system contained ?langue=... in the query.

bobince
A: 

Beside that what bobince already said, try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)langue=(\w{2}.*)
RewriteCond %1lang=%3 ^(([^&]*&)*)id_([\w]+)=([1-9]+.*)
RewriteRule .* $0?%1type=%3&id=%4

The substitution URL must be adjusted to your needs but the query substitution should be correct.

Gumbo