Jump to content

How to troubleshoot: non-virtual folders returning PW 404?


MarcC
 Share

Recommended Posts

I just tried to install Piwik but when I went to http://www.example.com/piwik, I got the Processwire 404 page. I tested this in other ways, creating different folders and they all return 404s.

Here are the lines in .htaccess that should be keeping this from happening:

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

Where should I start to troubleshoot this? I hesitate to contact the web host, as I know support techs sometimes change things in .htaccess willy-nilly...

Link to comment
Share on other sites

Silly question, but are the permissions set correctly on Piwik's folder and files? That would be my first guess.

Also might be an idea to test temporarily by selecting and cutting all the contents of your .htacess file so it's blank and see if that allows you to access Piwik, then put it back to how it was quickly (assuming it's a live site).

Link to comment
Share on other sites

Yeah, permissions and ownership look OK. The folder is accessible just fine without .htaccess. Here is the full file:

#################################################################################################
# START PROCESSWIRE HTACCESS DIRECTIVES
# @version 2.1
#################################################################################################
# -----------------------------------------------------------------------------------------------
# Don't show directory indexes, but do follow symbolic links
# -----------------------------------------------------------------------------------------------
Options -Indexes
Options +FollowSymLinks
# -----------------------------------------------------------------------------------------------
# Let ProcessWire handle 404s
# -----------------------------------------------------------------------------------------------
ErrorDocument 404 /index.php
# -----------------------------------------------------------------------------------------------
# Handle request for missing favicon.ico/robots.txt files (no ending quote for Apache 1.3)
# -----------------------------------------------------------------------------------------------
<Files favicon.ico>
 ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>
<Files robots.txt>
 ErrorDocument 404 "The requested file robots.txt was not found.
</Files>
# -----------------------------------------------------------------------------------------------
# Protect ProcessWire system files (part 1)
# -----------------------------------------------------------------------------------------------
<FilesMatch "\.(inc|info|module|sh|sql)$|^(\..*)$">
 Order allow,deny
</FilesMatch>
# -----------------------------------------------------------------------------------------------
# Override a few PHP settings that can't be changed at runtime (not required)
# -----------------------------------------------------------------------------------------------
<IfModule mod_php5.c>
 php_flag magic_quotes_gpc  off
 php_flag magic_quotes_sybase  off
 php_flag register_globals  off
</IfModule>
# -----------------------------------------------------------------------------------------------
# Set default directory index files
# -----------------------------------------------------------------------------------------------
DirectoryIndex index.php index.html index.htm
# -----------------------------------------------------------------------------------------------
# ProcessWire requires mod_rewrite
# -----------------------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
 RewriteEngine On
 # -----------------------------------------------------------------------------------------------
 # Set an environment variable so the installer can detect that mod_rewrite is active.
 # -----------------------------------------------------------------------------------------------
 SetEnv HTTP_MOD_REWRITE On
 # -----------------------------------------------------------------------------------------------
 # Optional: Set a rewrite base if rewrites aern't working properly on your server.
 # And if your site directory starts with a "~" you will most likely have to use this.
 # -----------------------------------------------------------------------------------------------
 # RewriteBase /
 # RewriteBase /pw/
 # RewriteBase /~blah/
 # -----------------------------------------------------------------------------------------------
 # Access Restrictions: Keep web users out of dirs that begin with a period
 # -----------------------------------------------------------------------------------------------
 RewriteRule "(^|/)\." - [F]
 # -----------------------------------------------------------------------------------------------
 # Optional: Redirect users to the 'www.' version of the site (uncomment to enable).
 # For example: http://processwire.com/ would be redirected to http://www.processwire.com/
 # -----------------------------------------------------------------------------------------------
 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 # -----------------------------------------------------------------------------------------------
 # Access Restrictions: Protect ProcessWire system files (part 2)
 # -----------------------------------------------------------------------------------------------
 RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
 RewriteCond %{REQUEST_URI} (^|/)site/assets/(cache|logs|backups|sessions|config|install)($|/.*$) [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/install($|/.*$) [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/config\.php$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)(wire|site)/templates-admin($|/|/.*\.(php|html?|tpl|inc))$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/templates($|/|/.*\.(php|html?|tpl|inc))$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/assets($|/|/.*\.php)$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)wire/(core|modules)/.*\.(php|inc|tpl|module)$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site/modules/.*\.(php|inc|tpl|module)$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)(COPYRIGHT|INSTALL|README|htaccess)\.txt$ [OR]
 RewriteCond %{REQUEST_URI} (^|/)site-default/
 RewriteRule ^.*$ - [F,L]
 # -----------------------------------------------------------------------------------------------
 # Ensure that the URL follows the name-format specification required by ProcessWire
 # -----------------------------------------------------------------------------------------------
 RewriteCond %{REQUEST_URI} "^/~?[-_.a-zA-Z0-9/]*$"
 # -----------------------------------------------------------------------------------------------
 # 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)
 # -----------------------------------------------------------------------------------------------
 # Optional: Don't send missing image requests to ProcessWire (uncomment below to enable).
 # This might be helpful if you are launching a new site and lots of images have moved.
 # It will reduce the load on the server not to have ProcessWire trying to serve those requests.
 # -----------------------------------------------------------------------------------------------
 # RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|ico)$ [NC]
 # -----------------------------------------------------------------------------------------------
 # Pass control to ProcessWire if all the above directives allow us to this point.
 # For regular VirtualHosts (most installs)
 # -----------------------------------------------------------------------------------------------
 RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]
 # -----------------------------------------------------------------------------------------------
 # If using VirtualDocumentRoot: comment out the one above and use this one instead.
 # -----------------------------------------------------------------------------------------------
 # RewriteRule ^(.*)$ /index.php?it=$1 [L,QSA]
</IfModule>
#################################################################################################
# END PROCESSWIRE HTACCESS DIRECTIVES
#################################################################################################
Link to comment
Share on other sites

I contacted support and they said "yup, must be something in .htaccess." Very helpful! But at least they didn't break the site. :) Is there anything you guys think I should try?

Edit: the folder /forms works fine but /piwik doesn't. Weird!

Link to comment
Share on other sites

Edit: the folder /forms works fine but /piwik doesn't. Weird!

That's pretty bizarre. Have you tried another browser, just in case something is going on with the cache? Also, none of the URLs you mentioned have trailing slashes--try adding one (if you haven't already). Can you give us an "ls -al" of the piwik directory and the contents within it? I'm interested to see the permissions and what's in there.

Link to comment
Share on other sites

Is there another htaccess inside Piwik's folder that might be interfering?

For kicks and giggles, I moved the Piwik files to /piwik2 and then tried to access the empty /piwik folder. In a different browser. On a different machine. With trailing slashes. Same result. And that's an empty folder! Of course accessing /piwik2 doesn't work either.

The only thing that's different between /forms and /piwik, that comes to mind: the /forms folder was created some time ago, back when I was still accessing the site via http://IP/~username. The new folders were created after I got a new IP address and updated the DNS so I can go to example.com now. No idea why that would affect anything.

ls -al result (changed user/group names)

drwxr-xr-x 9 example example 4096 Jul 4 13:10 forms/ (working)
drwxr-xr-x 2 example example 4096 Aug 17 00:01 piwik/ (not working, empty)
drwxrwxr-x 12 example example 4096 Aug 15 21:34 piwik2/ (not working)

piwik2 folder ls -al results:

drwxrwxr-x 12 example example 4096 Aug 15 21:34 ./
drwxr-x--- 20 example nobody 4096 Aug 17 03:09 ../
-rw-rw-r-- 1 example example 676 Aug 12 09:05 composer.json
drwxrwxr-x 2 example example 4096 Aug 15 21:34 config/
drwxrwxr-x 25 example example 4096 Aug 15 21:34 core/
-rw-rw-r-- 1 example example 1611 Mar 20 01:23 index.php
drwxrwxr-x 2 example example 4096 Aug 15 21:34 js/
drwxrwxr-x 2 example example 4096 Aug 15 21:34 lang/
-rw-rw-r-- 1 example example 6070 Feb 13 2012 LEGALNOTICE
drwxrwxr-x 20 example example 4096 Aug 15 21:34 libs/
drwxrwxr-x 6 example example 4096 Aug 15 21:34 misc/
-rw-rw-r-- 1 example example 19990 Jul 31 19:43 piwik.js
-rw-rw-r-- 1 example example 2911 Aug 1 23:27 piwik.php
drwxrwxr-x 45 example example 4096 Aug 15 21:34 plugins/
-rw-rw-r-- 1 example example 2640 Mar 5 20:17 README
drwxrwxr-x 2 example example 4096 Aug 15 21:34 tests/
drwxrwxr-x 3 example example 4096 Aug 15 21:34 themes/
drwxrwxr-x 2 example example 4096 Aug 15 21:34 tmp/

Now, the part about /public_html (../ above) being part of group nobody ...is that normal? I just noticed that.

Link to comment
Share on other sites

Maybe the nobody-group thing isn't a big deal. I have another site, same server, same group for public_html, and new folders work fine alongside ProcessWire.

Here's a support reply:

Hi Marc,

Here's the exact rule that interferes with this subdirectory:

RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]

If you temporarily disable it - the subdirectory will load properly.

Unfortunately, this isn't something we can assist you with fixing as we're not web developers and thus don't have extensive experience with .htaccess coding.

Good guys though; they're generally helpful. Anything I should try tweaking with that specific rule? Seems to work even on other PW sites on the same server. And it's kind of an important rule, I understand...

Link to comment
Share on other sites

The problem might be that the home page template has url segments enabled?

URL segments box is unchecked for Home template.

Now I'm starting to wonder what I should do instead of using subfolders. :) Put everything under /forms? Ha ha

Link to comment
Share on other sites

OK, here's the latest:

I turned directory indexes back on and now I can access any subfolder. :-/ (feeling a bit stupid there..didn't realize ProcessWire's 404 page would handle those if indexes were turned off)

However, I still can't access the /piwik2 folder with Piwik's files in it. I believe this might be due to Piwik's index.php being included in ProcessWire's .htaccess rules. Is that possible? There's no .htaccess in Piwik's folder, so I'm wondering if I should put one there. Advice?

Link to comment
Share on other sites

Marc is this server running Apache or some Apache clone? The reason I ask is that it's not behaving like Apache. ProcessWire should never get control of the request due to these two directives:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

That basically says: "In order to give control to PW, the requested file or directory must not exist."

So assuming it's actually Apache and it understands those directives, we have to look at why it's not associating that with what's actually on the file system. I would probably try adjusting the RewriteBase line to be "RewriteBase /". If that doesn't work, you might want to look at enabling the VirtualDocumentRoot line (at the bottom of the htaccess file).

The 'nobody' permission should be okay. That's most likely the user that Apache is running as.

You've got me curious :) please let me know what you find.

Link to comment
Share on other sites

Thanks, Ryan. Well, the httpd service is showing version 2.2.22...that's got to be Apache, right? If maybe not, I can make double-sure...this is on Centos 5.8.

I did try uncommenting "RewriteBase /" just now, but the problem persisted. Same with the VirtualDocumentRoot line (uncommented separately from RewriteBase)...same when I uncomment both directives (and comment out the non-virtualdocumentroot line).

I can access e.g. /piwik2/piwik.js just fine (it lists out in my browser)...this is all happening when I am calling PHP files in that folder, index.php or piwik.php, etc.

Link to comment
Share on other sites

It's quite a mystery. Can't say as though I've seen something like this before. It has me wondering if there is some mod_security setup or something else that is interfering with the usual behavior... that's the only thing I can guess, but I'll keep thinking.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...