S
S
sluchetsya2017-03-03 17:10:06
htaccess
sluchetsya, 2017-03-03 17:10:06

How to strip part of URL from URL using htaccess?

Greetings.
There are pages like site.ru/cat1/cat2/art.htm?fb_comment_id=12345&start=2 And the numbers in the segment id=12345 are always different.
I don’t understand how to cut out the fb_comment_id=123456789& part using htaccess to get pages like site.ru/cat1/cat2/article.html?start=2
I tried this:

RewriteCond %{QUERY_STRING} ^fb_comment_id= [NC]
RewriteRule (.*) $1? [R=301,L]

All that I did was to completely remove all the signs after the question mark, but not to cut out this particular segment.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-03-07
@shambler81

if you need to list numbers
If you need to transfer some of the elements from the conda to the steering wheel
Use brackets to select (patern1)(patern2)
a in the steering wheel instead of $1 $2 use %1 %2 (bucks will remain for the steering wheel itself)
Example:

#RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
   # Проверяем, содержит ли домен www (в начале URL).
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

If you need to clearly
# 301 --- http://site.ru/cat1/cat2/art.htm?fb_comment_id=12345&start=2  => http://site.ru/cat1/cat2/article.html?start=2
RewriteCond %{QUERY_STRING} (^|&)fb_comment_id\=12345($|&)
RewriteCond %{QUERY_STRING} (^|&)start\=2 ($|&)
RewriteRule ^cat1/cat2/art\.htm$ /cat1/cat2/article.html?start=2 [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question