A
A
alenev2018-06-01 20:52:21
URL Handling
alenev, 2018-06-01 20:52:21

How to exclude from 301 redirect url with certain part?

In htaccess, with this line, all pages with .html at the end are sent with a 301 redirect to their counterpart without .html
RedirectMatch 301 (.*)\.html$ /$1/
I need this rule not to work for links that have the component .../ order/xxx.html. This option doesn't work for me:
RewriteCond %{REQUEST_URI} !^/order
RewriteRule ^(.*)\.html$ /$1/ [R=301,L]
This kind of exception doesn't work either:
RewriteCond %{REQUEST_URI} ! ^/order\.html$
Tell me, please, how to write an exception correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-06-02
@alenev

RedirectMatch 301 ^((?:[^/]*/)++(?<!/order/).*)\.html$ $1/

RewriteEngine On

RewriteCond %{REQUEST_URI} !/order/[^/]+$
RewriteRule ^(.*)\.html$ /$1/ [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question