N
N
NataliaCh2018-07-06 11:57:27
Apache HTTP Server
NataliaCh, 2018-07-06 11:57:27

How to get rid of extra characters in url after RewriteRule works?

Bali addresses like site.ru/article? art_id =10
Steel site.ru/article? id =10
You need to redirect from the old ones to the new ones.
I write the following rule:
RewriteCond %{QUERY_STRING} art_id [NC]
RewriteRule .* id [L,R=301]
The rule works, but after the redirect, the symbol %3f appears in the url :
site.ru/article?id=10%3f
write a rule?
I'm testing so far on the local (OpenServer)
PS. On a combat server (1Gb hoster), the redirect does not work at all. That is, I write something wrong ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-07-06
@NataliaCh

RewriteCond %{QUERY_STRING} ^art_(id=.*)
RewriteRule ^(article)$ /$1?%1 [R=301,L]

Add above other rules right after RewriteEngine On

V
Viktor Taran, 2018-07-06
@shambler81

RewriteCond %{QUERY_STRING} (^|&)art_id\=10($|&)
RewriteRule ^article$ /article\?id=10 [L,R=301]

But probably ID is some numbers that dynamically change depending on the url, so let's make a regular expression for all numbers at once
RewriteCond %{QUERY_STRING} (^|&)art_id\=([0-9]{1,})($|&)
RewriteRule ^article$ /article\?id=%2 [L,R=301]

Where ([0-9]{1,}) - at least one or more digits, we collect them into a group and substitute it into the rule through% 2 since this is the second group.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question