Y
Y
Ysery2019-10-22 11:22:22
htaccess
Ysery, 2019-10-22 11:22:22

Trimming everything (excluding a couple of "tails") after .html via htaccess?

Good day, experts.
There is this line

RewriteRule ^(.+?)\.html(?!/amp/).+$ https://%{HTTP_HOST}/$1.html [L,R=301]

It strips extra characters after .html (excluding .html/amp/ ). But .html does not cut requests of this kind ?<anything can be here>
How should it look like, so that "tails" with a question mark are also cut off, and the exception is extended to the existing /amp/ also .html?srek= ... and more .html?srp= ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2019-10-22
@shambler81

GET is not part of the url and RewriteRule cannot work with it.
In your case, if you need to remove get parameters in general, you can do this
the question at the end of the line will remove the get parameters,
but if you need to work with them, then here is an example of how to do it

# 301 --- http://www.test3.com/faq.html?faq=13&layout=bob => bbq.html
RewriteCond %{QUERY_STRING} (^|&)faq\=13($|&)
RewriteCond %{QUERY_STRING} (^|&)layout\=bob($|&)
RewriteRule ^faq\.html$ /bbq.html? [L,R=301]

(^|&) and ($|&) - just to ensure that the second parameter does not start with a question mark

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question