简体   繁体   English

在 processwire 设置中,如何在没有 404 错误的情况下加载自定义的与 processwire 无关的 PHP 文件? 需要进行哪些 .htaccess 编辑?

[英]Within a processwire setup how do you have a custom non-processwire-related PHP file load without 404 error? What .htaccess edits need to be made?

I am working on a client website that runs on Processwire.我正在开发一个在 Processwire 上运行的客户网站。 I am trying to set up a regular ol' PHP page outside of any processwire stuff that can just execute like a normal PHP page being served up.我正在尝试任何可以像正常 PHP 页面一样执行的过程线内容之外设置一个常规的 ol' PHP 页面。

Let's assume I am trying to set up "/foo/bar.php" at root where the page "bar.php" has this code:假设我正在尝试在页面“bar.php”具有以下代码的根目录下设置“/foo/bar.php”:

foo/bar.php foo/bar.php

<?php

    echo "Hello World";

?>

Presumably, if I visited example.com/foo/bar.php the server would see that that resource exists and serve up the content by showing the user "Hello World" in the browser.据推测,如果我访问example.com/foo/bar.php ,服务器会看到该资源存在并通过在浏览器中向用户显示“Hello World”来提供内容。 Instead, however, I get a 404 error that takes me to the PW 404 page.但是,我收到一个 404 错误,将我带到 PW 404 页面。

Within the root's .htaccess file I see this:在根的 .htaccess 文件中,我看到了这个:

  # -----------------------------------------------------------------------------------------------
  # 17. If the request is for a file or directory that physically exists on the server,
  # then don't give control to ProcessWire, and instead load the file
  # -----------------------------------------------------------------------------------------------

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !(favicon\.ico|robots\.txt)

I must not understand this correctly since the actual bar.php file does physically exist... yet it won't work.我不能正确理解这一点,因为实际的 bar.php 文件确实存在......但它不起作用。 If, however, I change the extension of bar.php to bar.txt the file does load at example.com/foo/bar.txt (displaying the PHP code shown above).但是,如果我将bar.php 的扩展名更改为 bar.txt 该文件会加载example.com/foo/bar.txt (显示上面显示的 PHP 代码)。

So, how can I adjust or update .htaccess to tell PW to ignore anything under /foo (including files and folders recursively) from being processed by PW?那么,如何调整或更新 .htaccess 以告诉 PW 忽略 /foo 下的任何内容(包括递归的文件和文件夹),以免被 PW 处理?

You shouldn't have to do anything.你不应该做任何事情。 As you suggest, those directives (although incomplete and not strictly correct) should already exclude requests for any physical file (and directory).正如您所建议的那样,这些指令(尽管不完整且不完全正确)应该已经排除了对任何物理文件(和目录)的请求。 What is more likely the issue is how PHP files are processed/handled on your server (CGI/reverse proxy?.) and the filesystem check is then failing for some reason.更可能的问题是 PHP 文件是如何在您的服务器(CGI/反向代理?)上处理/处理的,然后文件系统检查由于某种原因而失败。

As a workaround you could put a specific exception in for this subdirectory that is serving your PHP files.作为一种解决方法,您可以为这个为您的 PHP 文件提供服务的子目录放置一个特定的例外。 This could be implemented in a few ways... for example:这可以通过几种方式实现......例如:

  • Include another condition first on the list of conditions you posted:在您发布的条件列表中首先包含另一个条件

     RewriteCond %{REQUEST_URI} !^/foo/

OR或者

  • Include an exception at the top of the .htaccess file that prevents any further mod_rewrite directives being processed when this directory is requested (or rather, when a URL-path that starts /foo/ is requested)..htaccess文件的顶部包含一个异常,该异常会阻止在请求此目录时(或者更确切地说,当请求以/foo/开头的 URL 路径时)处理任何进一步的 mod_rewrite 指令。

     RewriteRule ^foo(/|$) - [L]

OR或者

  • Create another .htaccess in the subdirectory /foo that disables (or enables) the rewrite engine.在子目录/foo中创建另一个.htaccess以禁用(或启用)重写引擎。 mod_rewrite directives are not inherited by default, so this completely overrides the mod_rewrite directives in the parent .htaccess file.默认情况下不继承 mod_rewrite 指令,因此这完全覆盖了父.htaccess文件中的 mod_rewrite 指令。

     RewriteEngine Off

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

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