1

I want to redirect pages like :

example.com/fr/opportunites/?sector_cat=bourses-detudes&ajax_filter=true

To


example.com/fr/bourses-detudes/

the second page is a post type page created with WordPress

Is there any possibility to do that with htacees in litespeed server ?

Thanks a lot

LH AL
  • 11
  • 1
  • 3

1 Answers1

1

In order to match against the query string part of the URL you need to use mod_rewrite with a condition (RewriteCond directive) that specifically checks the query string. Other directives only check against the URL-path (which naturally excludes the query string).

So, from your example, to redirect from /fr/opportunites/?sector_cat=<value>&ajax_filter=true to /fr/<value>/ you would need to use something like the following at the top of your .htaccess file before the existing WordPress directives.

RewriteCond %{QUERY_STRING} ^sector_cat=([^&]+)&ajax_filter=true$
RewriteRule ^fr/opportunites/$ /fr/%1/ [QSD,R=302,L]

The URL parameters (sector_cat and ajax_filter) must match in the order stated and no other URL params are permitted. The value of the sector_cat parameter must also be non-empty, otherwise it matches any characters except for &.

The %1 backreference in the RewriteRule substitution contains the captured subpattern from the query string (ie. the sector_cat parameter value).

The QSD (Query String Discard) flag is necessary in order to remove the original query string from the redirected response.

There is no slash prefix on the RewriteRule pattern when used in .htaccess. So, ^fr/ matches /fr/ at the start of the URL-path.

Test first with a 302 (temporary) redirect to avoid potential caching issues and only change to a 301 (permanent) redirect (if that is the intention) once you have confirmed it works as intended.

MrWhite
  • 12,647
  • 4
  • 29
  • 41