最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - Access files at new location using old file paths

programmeradmin1浏览0评论

I have a bunch of posts that contain images with urls that follow this pattern:

.png

I've imported the posts into a new install of wordpress on the same domain with file structure where the files now reside at

.png

Because "example_directory" is now a category slug, I cannot simply update the new directory structure to mirror the old one.

How can I make the files inside new_directory appear when my browser tries to visit urls at directory/files?

I have a bunch of posts that contain images with urls that follow this pattern:

https://example/example_directory/files/2019/04/file.png

I've imported the posts into a new install of wordpress on the same domain with file structure where the files now reside at

https://example/new_directory/2019/04/file.png

Because "example_directory" is now a category slug, I cannot simply update the new directory structure to mirror the old one.

How can I make the files inside new_directory appear when my browser tries to visit urls at directory/files?

Share Improve this question asked Feb 26, 2021 at 4:07 KeyslingerKeyslinger 1439 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I believe I've found the solution. I add the following

RewriteRule ^example_directory/files/(.*) new_directory/$1

to my WordPress .htaccess rules like so:

RewriteEngine On
RewriteBase /
RewriteRule ^example_directory/files/(.*) new_directory/$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I couldn't get it working before and I think the key was moving the new RewriteRule directive to the line directly following RewriteBase /

发布评论

评论列表(0)

  1. 暂无评论