简体   繁体   English

Apache,在404上的mod_rewrite中,检查文件系统中的文件

[英]Apache, on 404 from mod_rewrite, check file system for file

At the moment, I'm migrating a site, and due to time constraints, we've migrated most to a CMS (Drupal), but still have some flat HTML sub sites that need to get served outside of this. 目前,我正在迁移一个网站,由于时间限制,我们已将大部分迁移到CMS(Drupal),但是仍然有一些扁平HTML子站点需要在此之外提供服务。

Now, config wise, I've setup Apache to pass requests for files that do exist and get served directly, rather than sending the request to the CMS: 现在,在配置方面,我将Apache设置为传递对确实存在并可以直接提供服务的文件的请求,而不是将请求发送到CMS:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

As we get more time, the team would like to slowly import the pages we've left out of the CMS from the file system, but we don't have the ability to easily delete those additional files from the file system once we've imported them to Drupal (service provider deploy method unfortunately - so not changable). 随着时间的流逝,团队希望从文件系统中缓慢导入我们从CMS中遗漏的页面,但是一旦我们将其从文件系统中删除,便无法轻松删除这些其他文件。将它们导入到Drupal(不幸的是,服务提供商的部署方法-不可更改)。

We're using the same URLs as the old site (maintaining legacy links/addresses and all that), so once we've recreated the page in the CMS, the above rewrite rule is still going to serve the page from the file system. 我们使用与旧站点相同的URL(保留旧的链接/地址等),因此,一旦在CMS中重新创建了页面,上述重写规则仍将通过文件系统为页面提供服务。

What I would like to do to get around this, is route all requests through Drupal using mod_rewrite, then if Drupal throws a 404, attempt to pull the URL from the file system, rather than what we have currently, which is if the file exists, serve that automatically. 为了解决这个问题,我想使用mod_rewrite通过Drupal路由所有请求,然后,如果Drupal抛出404,请尝试从文件系统中拉出URL,而不是从当前系统中拉出URL,即文件是否存在,自动投放。 From a day or so of searching, I can't find a way of achieving this, can't even really find a lot of people having run into this issue before actually. 从一天左右的搜索中,我找不到实现这一目标的方法,甚至实际上还没有找到很多真正遇到过此问题的人。

Naturally, if I had full control over our environment, it would be easy to just delete the underlying files once they've been migrated, but that's not so simple in this case. 自然,如果我对环境有完全的控制权,那么一旦迁移了基础文件就可以很容易地删除它们,但是在这种情况下并不是那么简单。

I also understand doing this will incur an overhead, but given this will only apply for a small part of the site, I'll be evaluating any solutions to see whether it is an acceptable compromise. 我也知道这样做会产生开销,但是鉴于这仅适用于网站的一小部分,因此我将评估所有解决方案,以了解这是否是可以接受的折衷方案。

Any thoughts? 有什么想法吗?

Can you add a RewriteCond that will kick in before what you have there that checks for specific paths and sends them directly to index.php? 您是否可以添加一个RewriteCond,它将在您检查特定路径并将其直接发送到index.php之前启动?

Something like 就像是

RewriteRule ^/some/path/to/file.html$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

It might get kind of unwieldy if you have a lot of disparate paths, it would be nicer if your existing static files had a nice regexable pattern 如果您有很多不同的路径,它可能会变得有些笨拙,如果您现有的静态文件具有很好的可重码模式,那就更好了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM