I am in the process of rebuilding a site in WordPress that was built 20+ years ago on an .asp framework. Forgive me if this is OT. I was hoping someone in WSE that has had to do a site move like this may have a solution.

I have tried the following Regex but does not seem to work:

Source URL: /(.*).aspx
Regular expression: checked ☑ OR Select "REGEX" after Source URL
Target URL: /$1/

For the pdf's - Here is an overview. Original folder structure for .asp site:


The WordPress upload folder structure would be something like this:


The problem: Many of the pdfs from the old site have links within them that link to other pdfs stored on the server. It is not feasible to go into all the pdfs and change the links to the new folder structure in WordPress. Ideally if a link in a PDF is


It will redirect to


All PDF docs carry the idential file name in WordPress. The problem area is everything between the .com and the file name :/

I ran across this expression in SO:

Source URL: ^\/([^\s\/]+\.pdf) Target URL: example.com/wp-content/uploads/2021/01/$1 

...but this will only redirect to one folder which does not work since I currently have 5 media folders in Year/Month format.


1 Answer 1


Answering this here to save others time if they run into a similar issue. Clarity on this issue provided in this answer on SO by Stephen Ostermiller

Regular expression redirects only work when all the information about the new location can be derived from the URL for the old location. That isn't the case here. You have new information in the new URLs. The data that the document was uploaded is now in the URL when it wasn't before. There is no way to write a single rule with a regular expression to redirect all the URLs.

You have a couple options:

  • Redirect each PDF URL individually
  • Upload your PDFs to your new site in their original locations.

For my situation option #1 works best as follows (sample redirect using redirection plugin):

Source URL: /folder/sub-folder/sub-folder/somepdf.pdf
Target URL: /wp-content/uploads/2022/07/somepdf.pdf

Create a CSV of the redirects and bulk upload.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.