Ty Bailey Ty Bailey - 5 months ago 12
PHP Question

Redirect old ASPX URL with commas to new PHP URL

I've searched around quite a bit for this, but haven't come across my exact issue.

I recently rebuilt an old

.aspx
site into WordPress, changing essentially every URL on the site. I have all the redirects in place, except there are a few URL's with commas in them that I can't seem to get to redirect.

The URLs with the commas display an Apache "Forbidden" page.

For example, I have the URL:
/resourceslearn/tools/checklists,-tips,-tools/whitepapers.aspx
that I need redirected to
/whitepapers/


I'm not very good with regular expressions, let alone htaccess rules, so please forgive me if what I have tried is completely wrong.

I've tried the following rules:

Redirect 301 /resourceslearn/tools/checklists(.+)-tips(.+)-tools/whitepapers.aspx$ /whitepapers/


Redirect 301 /resourceslearn/tools/checklists([^/]+)-tips([^/]+)-tools/whitepapers.aspx$ /whitepapers/


Redirect 301 /resourceslearn/tools/checklists,-tips([^/]+)-tools/whitepapers.aspx$ /whitepapers/


Redirect 301 /resourceslearn/tools/checklists([^,/]+)-tips([^,/]+)-tools/whitepapers.aspx$ /whitepapers/


Can anyone give me some assistance on how I can detect the comma in the URL and redirect it to the proper page?

Answer

You can not use Regex in Redirect , try RedirectMatch instead

RedirectMatch 301 ^/resourceslearn/tools/checklists(.+)-tips(.+)-tools/whitepapers.aspx$ /whitepapers/

Reference :

https://httpd.apache.org/docs/current/mod/mod_alias.html

Comments