301 Redirecting URLs Based on GET Variables in .htaccess

I have some dirty old urls like ...

http://www.example.com/bunch.of/unneeded/crap?opendocument&part=1

http://www.example.com/bunch.of/unneeded/crap?opendocument&part=2

... what I want to redirect to a newer, cleaner form ...

http://www.example.com/page.php/welcome

http://www.example.com/page.php/prices

I understand that I can redirect one page to another with a simple redirect i.e.

Redirect 301 / bunch.of / unneeded / crap http://www.example.com/page.php

But the original page does not change, only it is GET vars. I cannot figure out how to set the redirection to the value of these GET variables. Can someone help pls !? I am pretty comfortable with old regular expressions, so I can use pop-rewrite if I have to, but I don’t understand the syntax for rewriting GET vars, and I would rather avoid a performance hit and use the pure Redirect directive. Is there any way? and if not, can anyone understand me regarding the correct pl-rewrite syntax?

Greetings

Roger.

+3
source share
3 answers

URL , RewriteMap. - :

1 welcome
2 prices

, ( ):

RewriteMap examplemap txt:/path/to/file/map.txt

:

RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=([0-9]+)(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/%{examplemap:%2}? [L,R=301]
+5

@Jack Ross

RewriteCond %{QUERY_STRING} option=com_content&task=view&id=70&Itemid=82
RewriteRule ^index.php http://www.domain.com/business/banks/? [R=301,L]

? URL- , .

+1

RedirectMatch , URL-, . URL-, , , "opendocument & part = 1", "" ( URL- ), RewriteMap - , , , URL- page.php PHP.

: URL-, , , ,

RedirectPermanent http://www.example.com/bunch.of/unneeded/crap?opendocument&part=1 http://www.example.com/page.php/welcome
RedirectPermanent http://www.example.com/bunch.of/unneeded/crap?opendocument&part=2 http://www.example.com/page.php/prices
0

Source: https://habr.com/ru/post/1708464/


All Articles