Roman Sadovnik
Roman Sadovnik

Reputation: 1

Htaccess taugh redirection rule

I have to create such a redirection rule in HTACCESS that changes the first part of the URL (from "confindustria/verona/news.nsf/($linkacross)" to "new.bestrank.it/gate/news/documento?openform&id="), keeps unchanged the ID ("879D9288439B4C42C12588E1004BD915&restricttocategory=Credito%20Finanza%20Assicurazioni") but extracts a static piece of it in the middle ("?opendocument").

From

https://old.bestrank.it/confindustria/verona/news.nsf/($linkacross)/879D9288439B4C42C12588E1004BD915?opendocument&restricttocategory=Credito%20Finanza%20Assicurazioni

to:

https://new.bestrank.it/gate/news/documento?openform&id=879D9288439B4C42C12588E1004BD915&restricttocategory=Credito%20Finanza%20Assicurazioni

How should I write the rules for this?

The best I came up with is the following:

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/confindustria/verona/news.nsf/($linkacross)/( 879D9288439B4C42C12588E1004BD915)?opendocument(&restricttocategory=Credito%20Finanza%20Assicurazioni)/?\s [NC]
RewriteRule ^  https://new.bestrank.it/gate/news/documento?openform&id=%1%2? [R=301,NC,L]

Upvotes: 0

Views: 71

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133518

With your shown samples and attempts please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.

Either use following Rules OR use rules of OR here, use them one at a time only please.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/old-path/(id-3434)-newfolder(-5455)/?\s [NC]
RewriteRule ^  https://new-domain.com/new-path/%1%2? [R=301,NC,L]


OR as a Generic rules(not hardcoding digits after id) try following:

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/old-path/(id-\d+)-newfolder(-\d+)/?\s [NC]
RewriteRule ^  https://new-domain.com/new-path/%1%2? [R=301,NC,L]

Upvotes: 2

Related Questions