Home > OS >  Specific htacces redirect exception
Specific htacces redirect exception

Time:05-23

I have created a redirection in .htaccess file for specific condition:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^page/(.*) /clanky/?sf_paged=$1 [R=301,L]
</IfModule>

Example:

someone clicks on this link: https://example.com/page/2/ and they will be redirected to: https://example.com/clanky/?sf_paged=2/

This scenario works perfectly.

Now I need to make an exception for the case if a link will be: https://example.com/page/2/?s=zemedelec - (the excluding condition should be /?s=), in this case I don't want to use any redirection.

Any idea, how to make this exception?

CodePudding user response:

To make an exception on your existing rule for when the query string starts with the URL parameter s= then you can add the following condition (RewriteCond directive):

RewriteCond %{QUERY_STRING} !^s=
RewriteRule ^page/(.*) /clanky/?sf_paged=$1 [R=301,L]

The negated condition !^s= is successful when the query string does not start with s=.

(the excluding condition should be /?s=)

The above does not explicitly check that the URL-path ends in a slash, so it will also exclude requests of the form https://xxx.cz/page/2?s=zemedelec.

  • Related