B
B
bossigorxxx2021-10-25 21:29:28
htaccess
bossigorxxx, 2021-10-25 21:29:28

How to exclude categories from a redirect to a new domain?

hello there is this rule:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteCond %{HTTP_HOST} site.net
RewriteRule ( .*) https://site-net.turbopages.org/site.net/s/$1 [R=302,L]


This is a redirect from domain to domain on mobile pages for turbo.

How to exclude the lechenie-diarei/page/2 category redirect and the lechenie-diarei category itself from the redirect

Tried this but doesn't help

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile |palmos|webos" [NC]
RewriteCond %{HTTP_HOST} site.net
RewriteCond %{REQUEST_URI} !^/lechenie-diarei/page/.*$
RewriteRule (.*) https://site-net.turbopages.org/site.net/s/$1 [R=302,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-10-27
@bossigorxxx

How mod_rewrite actually works .

mod_rewrite runs the request over and over until it stops changing.
The [L] flag stops the current iteration of request processing. However, if the request was modified by those RewriteRules that still managed to work out, Apache will start the request processing cycle again from the first RewriteRule.

RewriteCond %{REQUEST_URI} !^/lechenie-diarei
This condition normally works only on the first iteration of request processing.
But when the wordpress CNC rule fires, the contents of %{REQUEST_URI} will change to /index.php and Apache will restart the request processing cycle from the first RewriteRule. Instead of %{REQUEST_URI} you can check %{THE_REQUEST}. There's always the original request in its entirety or so . You can also use the %{ENV:REDIRECT_STATUS} variable. The code with which the previous redirect ended is stored there. At the first iteration, this variable is empty.RewriteRule . /index.php [L]
RewriteCond %{THE_REQUEST} !^\S+\s/lechenie-diarei
RewriteCond %{THE_REQUEST} "! /lechenie-diarei"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} !^/lechenie-diarei

V
Viktor Taran, 2021-10-26
@shambler81

And if without a slash in front?
Yes, and do not claim that you have a redirect cache in your browser, you also need to drop it, but preferably check it in another browser or through services.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteCond %{HTTP_HOST} site.net
RewriteCond %{REQUEST_URI} !^lechenie-diarei/page/.*$
RewriteRule (.*) https://site-net.turbopages.org/site.net/s/$1 [R=302,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question