mod_rewrite subdirectory is triggering errors - php

I'm trying out mod_rewrite on a local playground using MAMP (I know), the rule I'm using seems to be fine according to answers here on stackoverflow, but I keep getting a 404 page, even tried looking at the apache server log, and it seems to be missing the file extension even though the rewrite rule includes it.
Here is my rule:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^test/([0-9]+)/$ public/test.php?id=$1 [NC,L]
Apache log entry:
[Sat Mar 02 00:24:02 2013] [error] [client 127.0.0.1] File does not exist: /Applications/MAMP/htdocs/site/public/test
I have verified it works by placing the same htaccess file inside the sub directory, instead of the root, oddly enough, that works.
The issue seems to be related to the fact .php is missing (based on the apache log).

Related

403 forbidden errors being served only for some users on some content

I have a VPS running Debian 7, with Virtualmin 4.12gpl and a very vanilla configuration of Apache 2.2.22, PHP 5.4.35 and MySQL 5.5.40 with WordPress 4.01.
I'm experiencing a very odd issue in which certain resources (images and stylesheets, for example) are generating 403 errors for some users and not for others.
For example, some users get a 403 when trying to load this stylesheet: http://lunchtime.org.uk/wp-content/themes/GLA5/style.css (I don't!)
Some users get a 403 when trying to load this image: http://lunchtime.org.uk/wp-content/themes/GLA5/img/podcast.png (I do!)
I've tried a few things:
Changing the permissions has no effect. I've even set it to 777 and the offending files still won't load. Additionally, I can see and download the files through FTP.
I thought mod_security might be the issue, but is not installed
The .htaccess file looks normal for a WordPress installation.
Disabling caching\permalink-related plugins, and clearing my own cache doesn't do anything
Using virtualmin's 'Fix file ownership and permissions' button does nothing.
I've also tried running (as an example)
chown -R www-data:www-data podcast.png
manually, but it has no effect.
It might be worth mentioning that I've set up the same site on two other VPSes, in the same way, and it worked just fine. I migrated all the content to this server on monday, just by copying all the files by FTP and doing a database export\import in phpMyAdmin.
Here's the .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I won't post the whole apache error log here, but every single error looks like this:
[Fri Nov 21 00:09:21 2014] [crit] [client 141.101.98.168] (13)Permission denied: /home/lunchtime/public_html/wp-content/themes/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
Thank you.
nvm figured it out
...I kid, I kid!
There was a recent update to apache that changed the syntax of the FilterProvider directive. As it turns out, the version of the HTML5 boilerplate .htaccess file I was using was using the old syntax.
If you're encountering this problem, open up your .htaccess file and do a search for
FilterProvider
According to this Github Comment (whose instructions I followed), you should change any line that looks like this:
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
Into this:
FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = 'text/html'"

Request exceeded the limit of 10 internal redirects when deployed on Heroku

I am trying to deploy the latest version of my code to Heroku (which works perfectly locally, the exact same code) and I see Error 500. When I look at heroku logs, I see the following error:
2014-06-15T12:41:20.661382+00:00 app[web.1]: [Sun Jun 15 12:41:20.555906 2014] [core:error] [pid 65:tid 139773788280576] [client 10.164.12.48:57546] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
I set the LogLevel to debug:
heroku config:add LOG_LEVEL=DEBUG
But I still get the same error. I also tried adding RewriteBase / to my .htaccess file in the main folder of CakePHP, as some people suggested:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
And I also tried it in the webroot folder, but still no luck!
People also say this could happen due to insufficient permission of /tmp/ folder, but when I change the permission to read and write Git does not see the change. I even force downgrade PHP when deploying on Heroku!
With all the suggestions, I still find it very weird, because I did not change anything in any configuration files nor did I change any permission on any file. Anyone any idea what could cause this? Please don't refer me to other posts in StackOverflow, as I've already seen all of them.
Update:
A rollback to the old code, gets the website working again, but the funny things is that it does not matter what I add to the code (even a line of code or an echo), it crashes the website! So I just want to say that it has nothing to do with what code I have written.
This is now fixed: https://devcenter.heroku.com/changelog-items/486
The underlying issue was the way requests to .php files were proxied to PHP-FPM using default rewrites, which would occasionally interfere with user-land rewrites.
However, what you should really be doing is set your document root so it's app/webroot/, instead of rewriting to that location first (and then having the .htaccess in there do another round of rewrites).
Create, add, commit and push a Procfile that looks like this:
web: vendor/bin/heroku-php-apache2 app/webroot/
Maybe you meant .+ in your second RewriteRule, so it does not apply to requests for / and cause you to loop.
Every time a substitution occurs in RewriteRule in htaccess, the entire set of rules runs again on the substitution.

Copied WordPress site now "blank"?

I just copied a site over to a new developmental subdomain for some changes. The copy went fine. I used rsync and all files are in place. I dumped the db contents and loaded them up.
Additionally I modified the wp-config.php so that it would have:
define('WP_HOME','http://www.dev.newdomain.tld');
define('WP_SITEURL','http://www.dev.newdomain.tld');
// Just trying to catch any error info:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
#ini_set('display_errors',0);
define('SCRIPT_DEBUG', true);
Posts, plugins, users, etc. all show up just fine on the wp admin interface, however NO content is being displayed on the front end.
If I modify an article from the wp admin, it edits just fine, however when I attempt to view a post I get the following in my browser:
Not Found
The requested URL /path-to-article/ was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
And the following in my apache error.log:
[Tue Feb 05 05:50:07 2013] [error] [client xxx.xxx.xxx.xxx] File does not exist: /home/username/dev.domain.tld/path-to-post
[Tue Feb 05 05:50:07 2013] [error] [client xxx.xxx.xxx.xxx] File does not exist: /home/username/dev.domain.tld/missing.html
This part leads me to believe that perhaps it is something going on with apache's .htaccess, however it seems to look okay:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And yes, I have disabled all plugins to see if there could be something going on there. Further, changing the theme to the default "Twenty Twelve" also does not help.
Additionally when looking at the generated page source, there is simply no content within the html.
All I see is a singular access in the access log for the web browser to the root / site resource with NO accompanying other resources (files, images, etc.)
What could be going on here as I am seemingly at an impasse with no errors within the logs whatsoever?
Check your database. Wordpress stores many URLs as absolute URLs, so that's why you might have problems.

File does not exist: sys_cpanel php

I am trying to set up my website on VPS (Virtual Private Server). When I browse a static file like abc.html it works well. However when I try to browse a file that has database connection I get 500 error: The request was not completed. The server met an unexpected condition.
So I thought my mysql credentials would be wrong. But they seem to be correct. When I go into CPanel and check the logs I find this:
[Sat Jun 02 08:19:26 2012] [error] [client XXX.XXX.XXX.XXX] File does not exist: /home/abv/public_html/abv/Connections/sys_cpanel, referer: http://XXX.XXX.XXX.XXX/~abv/abv/Connections/PowerCMSConnection.php
Googling it suggests that I have something wrong in my .htaccess file. But if it would have been wrong then why would the files that don't use database connection work?
Anyways, this is my .htaccess file:
##########################################
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\$ $1.html [nc]
Redirect 301 /business.html http://www.something.com/corporate-production-video
Redirect 301 /events.html http://www.something.com/london-videography
Redirect 301 /property.html http://www.something.com/property-on-video
Redirect 301 /weddings.html http://www.something.com/weddings-videographer
Redirect 301 /contact_us.html http://www.something.com/production-companies-music-video
Can somebody suggest what the error can be?
If your browser support Private Browsing (Fifefox, Incognito for Google Chrome and InPrivate for Internet Explorer), try opening the site after initializing such private browsing mode.
A while ago when I was configuring my webserver for redirects, it turned out that the browser saved the first redirect setting (301 means permanent redirection), and even though I altered the configuration and rebooted the server, my browser was using the same, bad, locally cached data. The issue for me was cleared after checking in private browsing mode.

Apache / Zend Framework - Error Log - Page Not found

This one is a little confusing to me.
I'm running a LAMP server with Zend Framework. I've spent a lot of time going over my error logs to try and clean-up any programming errors/bugs.
Most of my specific site errors are done but I looked into my general Apache error log:
/var/log/apache2/error.log
And I'm seeing a lot, almost constant, errors for "File does not exist" like the following (simplified for brevity):
[date] [error] [client #:#:#:#] File does not exist: /var/www/sites/[website folder]/public/explore
[date] [error] [client #:#:#:#] File does not exist: /var/www/sites/[website folder]/public/where-to-buy
[date] [error] [client #:#:#:#] File does not exist: /var/www/sites/[website folder]/public/products
And so on. These folders do not exist because all requests are suppose to be redirected into the index.php file and handled by Zend Framework. The actual controllers and actions exist, such that anyone going to:
http://www.example.com/explore
or
http://www.example.com/where-to-buy/
will get the correct page via Zend Framework.
But I'm not understanding why all these errors are occuring?
If figure it might have something to do with the .htaccess file that redirects most requests (excluding style sheets, documents, images, etc) to the index.php script. This is what mine looks like:
RewriteEngine On
# make sure all requests go to 'www' sub-domain
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# Zend Framework, redirect requests to index.php
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Is Apache trying to resolve the request via an actual directory first and then passing the request to index.php? Which causes the error request?
I'm also not sure why this is getting dumped into the default error log, instead of the error log or the specific site. In other words, I have error logs for each domain such as "example.com_error.log". That might be another indication to the issue. It might be a sequence thing as "error.log" is tired to a "default" site.
Thanks for any insight!
Fozzy
From Regilero:
the fact this is going to the default log is effectively a good hint
on the problem, check the related access.log. Maybe some requests made
on a DNS name not handled in your virtualhost or by web clients not
using HTTP 1/1 (so with no host header) – regilero Oct 19 '11 at 22:52
I was able to compare the access.log with the error.log to investigate my issues.
It was awhile ago but I believe the issue was due to some script going directly to the server via an IP address and trying to use the directory structure from one of the virtually hosted domains.

Categories