Wednesday, September 21, 2022
HomeWordPress DevelopmentRegex for pdf's - Outdated .asp Web site folder construction to new...

Regex for pdf’s – Outdated .asp Web site folder construction to new WordPress Media Folder(s)


I’m within the strategy of rebuilding a web site in WordPress that was constructed 20+ years in the past on an .asp framework (suppose Dreamweaver) and am having a little bit of a problem making a RegEx for paperwork (.pdf, .doc, and so forth.)

Right here is an summary.
The unique construction for folders is what you’d anticipate on an outdated web site that has “grown legs” over the years- paperwork are uploaded in varied locations.

https://aspsite.com/parent_folder/somedocument1.pdf

https://aspsite.com/another_folder/somedocument2.pdf

https://aspsite.com/parent_folder/sub_folder/somedocument3.pdf

As you’re conscious – the WordPress add folder construction is one thing like this:

https://newsite.com/wp-content/uploads/2022/06/somedocument1.pdf
https://newsite.com/wp-content/uploads/2022/09/somedocument2.pdf

The issue is that each one the pdf docs from the outdated web site have references(hyperlinks) in them that hyperlink to different pdf docs saved on the server. It’s not possible to enter all of the pdfs and alter the hyperlinks to the brand new folder construction in WordPress. Ideally if a hyperlink in a pdf is

https://aspsite.com/parent_folder/somedocument1.pdf

It is going to redirect to

https://newsite.com/wp-content/uploads/2022/06/somedocument1.pdf

I’ve already ensured all of the pdf docs carry the idential file title in WordPress. The issue space is all the things between the .com and the file title :/

Is there a RegEx expression that may handle this being that the folder construction just isn’t 1:1 (some due to location on the outdated server and a few due to how WordPress handles media attachments and the month the doc was uploaded)

There’s a related put up right here https://stackoverflow.com/questions/69202068/redirect-only-pdf-files-from-html-site-to-new-wordpress-directory-using-redirect from however I cannot appear to get it working as desired as a result of I’ve 2-3 uploads folders they might must go to.

Supply URL: ^/([^s/]+.pdf) Goal URL: newsite.com/wp-content/uploads/2021/01/$1 

However that’s redirecting to a particular media folder so it doesn’t work as anticipated since media folders content material (and placement of file) modifications month-to-month.

Sidenote: I did think about creating sub-folders elsewhere on the brand new server to match the prevailing setup however that might put them exterior the wordpress atmosphere, trigger points with web site search, and another variety of potential conflicts.

Admire any enter you will have.
Thanks!

Notice: Xpost from stackexchange for extra WordPress centered viewers.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments