0

I have an old website with Joomla 1.5. It has some strange links with GET-parameters, like this:

http://www.primavista.ru/images/stories/catalog/?rand=1186511674
http://www.primavista.ru/images/stories/catalog/?rand=145388433
http://www.primavista.ru/images/stories/catalog/?rand=1553907057
http://www.primavista.ru/images/stories/catalog/?rand=1563973527
http://www.primavista.ru/images/stories/catalog/?rand=1981273478
http://www.primavista.ru/images/stories/catalog/?rand=2139631800
http://www.primavista.ru/images/stories/catalog/?rand=366928750
http://www.primavista.ru/images/stories/catalog/?rand=524689684
http://www.primavista.ru/images/stories/catalog/?rand=569077423
http://www.primavista.ru/images/stories/catalog/?rand=573405687
http://www.primavista.ru/images/stories/catalog/?rand=879649167

I want make redirect theses links to the homepage. I tried some different instructions in .htaccess:

RewriteCond %{QUERY_STRING} ^/images/stories/catalog/?rand=([0-9]*)$
RewriteRule ^(.*)$ https://primavista.ru/? [R=301,L]

RewriteCond %{QUERY_STRING} ^/images/stories/catalog/?rand=(.*)$
RewriteRule ^(.*)$ https://primavista.ru/? [R=301,L]

RewriteCond %{QUERY_STRING} (^|&)(rand)=[^&]+ [NC]
RewriteRule ^images/stories/catalog(/.*)?$ https://primavista.ru/? [R=301,L,NC]

But no one not working. Maybe here someone can help me with this. Thanks

Zeus07
  • 33
  • 4

1 Answers1

1

This probably is what you are looking for:

RewriteEngine on
RewriteCond %{QUERY_STRING} rand=\d+
RewriteRule ^/?images/stories/catalog/?$ / [R=301,L]

It is a good idea to start out with R=302 temporary redirections and to only change that to R=301 permanent redirections one you are satisfied with everything. That prevents nasty caching issues on the client side ...

UPDATE: Your comment below indicates that you actually ask to remove the GET parameter in the redirected request, which you never mentioned before...

You can use the additional QSD flag for that:

RewriteEngine on
RewriteCond %{QUERY_STRING} rand=\d+
RewriteRule ^/?images/stories/catalog/?$ /? [R=301,QSD,L]
arkascha
  • 41,620
  • 7
  • 58
  • 90
  • Sorry, but not working – Zeus07 Nov 18 '21 at 13:40
  • And "not working" means what exactly? Do you get an unexpected response? No response at all? An error? Does the universe implode? – arkascha Nov 18 '21 at 17:57
  • I have redirect on the homepage, but GET-parametr exist – Zeus07 Nov 21 '21 at 11:56
  • You never mentioned an issue with that parameter before. If the issue is just removing that parameter then have a try using the variant I added as UPDATE to the answer above. – arkascha Nov 21 '21 at 15:06
  • Thanks, I'd tried, but after redirect I'll look this URL: https://www.primavista.ru/?rand=1186511674 – Zeus07 Nov 22 '21 at 16:22
  • Please give an example for the request, the expected result and the actual result. We need to be precise here. – arkascha Nov 22 '21 at 16:48
  • Example broken link: http://www.primavista.ru/images/stories/catalog/?rand=1186511674 Must be redirect on: https://primavista.ru – Zeus07 Nov 22 '21 at 18:38
  • I made another slight change to the second, updated implementation. Have a try. – arkascha Nov 22 '21 at 20:50
  • The same result. I go to the homepage with GET-parameter – Zeus07 Nov 23 '21 at 09:06
  • No, things are fine now when I test the URL you gave above in the comment. Could it be that you are looking at cached results? Please test using a fresh anonymous browser window. – arkascha Nov 23 '21 at 10:05