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

database - Having all "non-PHP" files on a different server

programmeradmin2浏览0评论

I would like to seperate my .php files from all the other files (images, scripts etc.) wordpress uses. So I put them on different servers.

I can make the files known to my wordpress site by simply setting "siteurl" and "home" to the url of the fileserver. This works fine for images, but breaks everything else ( like everyone would have expected )

Does anyone know of a more viable option to do this?

I would like to seperate my .php files from all the other files (images, scripts etc.) wordpress uses. So I put them on different servers.

I can make the files known to my wordpress site by simply setting "siteurl" and "home" to the url of the fileserver. This works fine for images, but breaks everything else ( like everyone would have expected )

Does anyone know of a more viable option to do this?

Share Improve this question asked Jun 21, 2019 at 9:03 JungeJunge 1032 bronze badges 3
  • 1 You could sign up for a CDN server, which there are even free ones. Most caching plugins have a built-in feature for CDN, which exactly does what you need. – Johansson Commented Jun 21, 2019 at 10:02
  • I am currently using AWS Cloudfront as a CDN. My problem does not lie in exposing the files, but in making them known to Wordpress (as in: Wordpress does still think all its files would be on the local filesystem) Thanks for the help so far and please tell me know if I misunderstood you, or if CDN does more than I think. – Junge Commented Jun 21, 2019 at 11:03
  • Cloudflare uses a different method, which leaves the URLs intact while the CDN is enabled. But if you wish to also load them from a different URL, you could try a service that is just an standalone CDN. – Johansson Commented Jun 21, 2019 at 19:35
Add a comment  | 

1 Answer 1

Reset to default 0

A couple of things: there are robust CDN plugins that you should use instead of trying to do this manually. That'll handle performance if that's the motivation for separating php from other files.

If your concern is just that you like to separate them in your source because of personal aesthetic code organization reasons, you should try this only in your own code (private plugin or theme) to reduce the surface area of the problem.

Certainly don't try to move the WP Core files (CDN plugins copy to CDN, rather than move). And 'simply setting "siteurl" and "home" to the url of the fileserver' is also certainly the wrong move, as you know, lol. WordPress is fundamentally built on the assumption that the files exist together: Think about image editing features in WP; the file needs to be in the same place for the php to manipulate it.

If you are dealing with just your own code organization, then you can avoid issues like file_exists() coming up false (and require causing fatals) because it's on the wrong server. From there, you can write wrapper functions around WP apis to handle the new URLs, or perhaps use some rewrites on requests to certain file types within just your own folder.

There is a WP rewrite API for that, but the knowledge is mostly in knowing Apache's rewriting.

TLDR: I think you either use a CDN Plugin, or the WP Rewrite API is what you need.

发布评论

评论列表(0)

  1. 暂无评论