2

I am working on a client website that runs on 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.

Let's assume I am trying to set up "/foo/bar.php" at root where the page "bar.php" has this code:

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. Instead, however, I get a 404 error that takes me to the PW 404 page.

Within the root's .htaccess file I see this:

  # -----------------------------------------------------------------------------------------------
  # 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. 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).

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?

Art Geigel
  • 1,915
  • 3
  • 22
  • 24
  • You shouldn't have to do anything. What is the complete rule in `.htaccess`? `RewriteCond` directives (ie. _conditions_) don't actually do anything by themselves. – MrWhite Mar 25 '21 at 14:54

1 Answers1

1

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.

As a workaround you could put a specific exception in for this subdirectory that is serving your PHP files. 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).

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

OR

  • Create another .htaccess in the subdirectory /foo that disables (or enables) the rewrite engine. mod_rewrite directives are not inherited by default, so this completely overrides the mod_rewrite directives in the parent .htaccess file.

    RewriteEngine Off
    
MrWhite
  • 43,179
  • 8
  • 60
  • 84