Consultation regarding redirection.
I ’m sorry if it ’s very easy…

I'm currently trying to set redirects for some URLs in my site.
I am in trouble because the URL part with parameters does not skip well.

For redirect images,

<old URL>
* Different parameters are attached to ○○○○
* There are hundreds of other URLs that are different in ○○○○.
<New URL>
* Skip everything to the above URL
I want to


Examples that I have verified and did not work are as follows.

■ How to redirect to the URL before the parameter (https://abc.com/abc/index.php)
RewriteEngine on
RewriteRule ^ abc/index.php $https://def.com/def/ [L, R = 301]

* The above description did not redirect like an image

■ How to redirect by directory
RewriteRule ^ abc (. *) $https://def.com/def$1 [R = 301, L] R = 301, L]

* This method can not be used because there was PHP in the first place that you do not want to skip

■ How to write each URL with parameters
RewriteEngine on
RewriteCond% {QUERY_STRING} cswkd = ○○○○
RewriteRule ^ abc/index.php $https://def.com/def/? [L, R = 301]

※ Although it was redirected well, I abandoned it because I would write a tremendous number

or more.

If i have any good solution, please let me know.
If there is any missing information, please let me know.

  • Answer # 1

    Regular expressions should be used to condition many patterns.

    What kind of value can be entered in cswkd = for the time being?

    RewriteEngine on
    RewriteCond% {REQUEST_URI} ^ abc/index.php $
    RewriteCond% {QUERY_STRING} (^ cswkd = |&cswkd =) ([^&] +)
    RewriteRule (. *) Https://def.com/def [R = 301, L]

    This way of writing

    ①cswkd = is empty


    ② cswkd = is included in an unexpected place


    is not redirected, so if you want to redirect them too, relax the% {QUERY_STRING}condition as follows. . .

    When redirecting ①

    RewriteCond% {QUERY_STRING} (^ cswkd = |&cswkd =)

    When redirecting ②

    RewriteCond% {QUERY_STRING} cswkd = ([^&] +)

    To redirect both ① and ②

    RewriteCond% {QUERY_STRING} cswkd =

    On the other hand, if strictly following the URL formathttps://abc.com/abc/index.php?cswkd=○○○○It is also possible not to be redirected if it contains or does not have a cswkd value. . .

    RewriteCond% {QUERY_STRING} ^ cswkd = ([^&] +) $

    If there is a rule for the value passed tocswkd =,
    RewriteCond% {QUERY_STRING} (^ cswkd = |&cswkd =) ([^&] +)
    If the([^&] +)at the end of is written with a regular expression that conforms to the rules, it can be redirected strictly.

    Although it doesn't redirect well,
    Depending on the server settings, the obtained value of the variable% {XXX_XXX}used for the condition may change, so if you check whether it is the expected value, you may find the cause.

    * Since the presented code includes unverified ones, please check the actual operation carefully ^^