Htaccess redirect not working with ? symbol

I am trying to redirect a page with symbols in .htaccess, but it’s not working:

The folder was in uppercase, I renamed it to lowercase.

RedirectMatch 301 /FOLDER/?article=hello/

I know it’s because of the ? symbol, hope someone can help.

Have you tried Redirect rather than RedirectMatch?

Yes, and it did not work.

Would it work to redirect the whole of FOLDER to folder?

RewriteEngine on
RewriteRule ^FOLDER/(.*)$ /folder/$1 [R=301,NC,L]

The question mark has meaning in regular expressions. eg. “match but don’t capture”, “zero or one”

When you want to match a character for what it is and not have it be used as it’s regex meaning, the typical way is to escape it so regex uses it as the literal character.

eg. where /foo?bar/ could match both “foobar” and “fobar”, /foo\?bar/ would match “foo?bar”

1 Like

Nope, that didn’t work either.

As for the other reply, there was no example really and I was clueless about it.

What @Mittineague is saying is you need a backslash before the question mark.

(Not sure why I didn’t think of that in the first place!)

1 Like

So it would be like this?

RedirectMatch 301 /FOLDER/\?article=hello/

Still didn’t work.

There are 2 question marks… :slight_smile:


I tried the following and still did not work:
RedirectMatch 301 /FOLDER/\?article=hello/\?article=hello/
Redirect 301 /FOLDER/\?article=hello/\?article=hello/

Unless you have an undisclosed reason for using RedirectMatch that is, to capture a portion of the request and use it, I really think Redirect is what you want

From what I see, it looks like the only difference is uppercase to lowercase. If so, all you need to do is worry about that.
Redirect 301 “/FOLDER” “”

This includes requests with GET parameters, such as, it will be redirected to Note that POSTs will be discarded.

1 Like

That worked.

Many thanks.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.