Link to home
Start Free TrialLog in
Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on

Need a Regex URL Ending in a Quotation Mark (")

I need to redirect this url
https://www.bensherbsplace.com/success_stories_for_pets_sp_195/"   

Open in new window

I have tried ^/(.+)/%22$ but there is no match.  How can I match a quotation mark?

Thanks,

Randal
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Try \? instead of the %22 that you have now
Avatar of sharingsunshine

ASKER

Thanks for getting back to me.  That didn't work and I have left it in place in case that will help you to troubleshoot.  Here is what I am matching to.

^/(.+)/\?$

Open in new window

What are you using to do the redirect? A WordPress plugin? htaccess file?
You may be able to match the " character with just \"
Your URL does not contain a question mark? Why would you want to use it then in a regexp?
I wouldn't but I was going by what you suggested
Try \? instead of the %22 that you have now                                  

Open in new window

I tried the straight " and it didn't work.  My host, Kinsta has a redirect tool.  What is the encoded value for a "?
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also try ["] to match a double quote.
I suggest you start by getting a redirect working that's almost what you want, and then going from there.

When testing your redirect, ensure you don't use a 301 redirect, as browsers will cache the redirect and cause major problems. 302 is better. This is very important, as you can't get the general public to clear their browser cache once they've cached an incorrect redirect. It will just keep on redirecting them to the wrong place, potentially for months.

So start with something like:
^/success_stories_for_pets_sp_195/

Open in new window

and ensure it's working. Note that I haven't included a $ on the end, so URLs that start with that path will all get redirected.

Then start trying to target the double quote. Perhaps firstly try:
^/success_stories_for_pets_sp_195/\"

Open in new window

and:
^/success_stories_for_pets_sp_195/["]

Open in new window

and if those didn't work, you could try:

^/success_stories_for_pets_sp_195/[^\s\w\-]

Open in new window

[^\s\w\-] matches a single character that's not a alphanumeric character or underscore (the \w), or a space (\s) or a dash character. ie it will target more than just a " character, but that might still provide a practical solution if it doesn't impact any other traffic.
I misread the question - reading question mark instead of quotation mark.. :( My suggestion would have been \" instead - since you already tried that I suggest you follow up with what Terry is suggesting.