0

I would like to redirect via a RewriteRule (mod_rewrite) enabled in httpd.conf my URL:

https://mysite.domain.tld/index_php_file.php?ab=ident_keys&ac=5GU7VBNAH45DA5

TO:

https://mysite.domain.tld/index_php_file.php?ab=ident_key_1024&ac=5GU7VBNAH45DA5

I have tried it with a number of rules without luck:

RewriteCond %{HTTP_HOST} hmysite.domain.tld
RewriteRule ^/index_php_file\.php\?ab=ident_keys&ac=$ https://hmysite.domain.tld/index_php_file.php?ab=ident_key_1024&ac= [R=301,L,QSA]

nor

RewriteCond %{QUERY_STRING} ^ac=(.*)$
RewriteRule ^/?([a-z-0-9-_.]+)$ /$1/index_php_file.php?ab=ident_key_1024&ac=%1 [L,R=301]

seems to rewrite the URL.

Any suggestions on what I'm missing?

Thank you very much.

baron
  • 129
  • 1
  • 3
  • 16

1 Answers1

0

I found the solution, it may help someone.

RewriteCond %{QUERY_STRING} ac=([A-Z0-9]+)
RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index_php_file.php?ab=ident_key_1024&ac=$1 [R=301,L]

It is enough to look for the string (containing UPPERCASE chars and numbers only) with the RewriteCond and rewrite the URL RewriteRule to the desired format and append the value of the variable from the query.

Do not forget to enable the mod_rewrite module within Apache. To take effect a restart is also necessary of course.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
baron
  • 129
  • 1
  • 3
  • 16