Please see the bottom section of this guide:
https://redirection.me/support/problems/url-not-redirecting/
Your regex needs the leading /
to be included – ^/generator/assets/(.*)
Thanks @johnny5 – that did the trick. It now redirects and displays the correct PDF.
Can I also ask if there is a way to redirect only files that are PDFs?
Basically, now I want to try redirecting just PDFs that are found under the root directory to the uploads directly. But I need to make sure that I don’t end up sending all pages at the root level to the uploads directory.
So I want it to do something like this:
From http://www.haregroup.com.au/*.pdf
To https://www.haregroup.com.au/wp-content/uploads/2021/01/*.pdf
I know that is the incorrect format, but I am trying to indicate that I want the redirect to pickup all files that end with .pdf, and redirect them to the same file name at the new location?
I see that the instructions say regex redirects might not work with PDF files, but since the current redirect is working, I would like to try this, if such a regex statement actually exists that would work.
Thanks again for any suggestions.
Cheers!
SunnyOz
Sure, you can use a regular expression:
https://redirection.me/support/redirect-regular-expressions/
I don’t think it says that a regex won’t work with PDF files. It just says that your server may handle PDFs differently.
OK. Thanks for the help.
I thought I had figured out a way works for me.
Source URL: ^/(.*).pdf
Target URL: https://www.haregroup.com.au/wp-content/uploads/2021/01/$1.pdf
It does work correctly as I wanted it to for this url: http://www.haregroup.com.au/How_was_your_last_pay_review_19Jan10.pdf
But unfortunately it is also picking up this URL, and basically giving it an infinite redirection loop; http://www.haregroup.com.au/generator/assets/How_was_your_last_pay_review_19Jan10.pdf
I had thought that putting the ^ before the / would limit it to just the root directory, and not pickup all subsequent directories also. I guess the (.*) is where it is allowing anything in the url that appears before the .pdf (including directories).
Can you give me an example of how to stop it looking beyond the root directory for a PDF?
-
This reply was modified 2 years, 7 months ago by SunnyOz.
Sorry.. I think I have it now, but would like to know why it works.
I got help from Stack Overflow (@Thefourthbird), with this suggestion:
Source URL: ^\/([^\s\/]+\.pdf)
Target URL: https://www.haregroup.com.au/wp-content/uploads/2021/01/$1
That seems to do the redirect for only PDFs in the root directory, and not allow other directories to be examined.
I am not actually sure why this works, and why his example with the
/ An unescaped delimiter must be escaped with a backslash (\)
works in your plugins regex (when my other examples with ‘unescaped delimiters’ have worked fine.
But I thought all this explanation might help your other users.
Thanks,
SunnyOz