3

To redirect

www.example.com/index.php?country=a

to

www.example.com/a/

tried:

RewriteCond %{QUERY_STRING} index.php?country=a [OR]
RewriteCond %{REQUEST_URI} index.php?country=a
RewriteRule ^ http://www.example.com/a/? [L,R=301]

Not works.

Notes:

1) This code is also a bad idea if a to be dynamic (60 countries in my list).

2) Anything after index.php?country=a e.g: index.php?country=a&p=d&xx=k to be removed.

  • Do you maybe want to do the opposite redirection? Why would you redirect "standard" url type to SEO type? – MilanG Apr 06 '16 at 07:18
  • Probably you missing my second note. I'm not looking for clean URLs. Trying to delete bunch of disabled URLs. –  Apr 06 '16 at 07:26
  • You could also just do this in the PHP application. Instead of returning the (old) page, just return a `header('Location: http://example.com/country');` – aross Apr 06 '16 at 08:05

3 Answers3

0

The variable %{QUERY_STRING} represents the query part (the part after the ?) of an url,

so You can not match the uri index.php in the pattern, try:

RewriteCond %{QUERY_STRING} ^country=([^&]+)(?:&(.*))?$ [NC]
RewriteRule ^ http://www.example.com/%1/? [L,R=301]

Or

RewriteCond %{THE_REQUEST} /index\.php\?country=([^&]+)
RewriteRule ^ http://www.example.com/%1/? [L,R=301]

Clear your browser's cache before testing these rules.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
0
RewriteRule ^/([a-zA-Z]+) index.php?country=$1 [NC,L]

It will help you to to have a clean URL from any value, not only 'a'

MoHo
  • 2,402
  • 1
  • 21
  • 22
0
RewriteRule ^a$ index.php?country=a [NC,L]

this one for sure works... Make sure the index.php?country=a is not in any sub-directory

MoHo
  • 2,402
  • 1
  • 21
  • 22