0

I have a website with a url that uses mod_rewrite to rewrite the files (all in the same folder).

The url is this shape: /sales/<category>

And this is translated by mod_rewrite below:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sales/([a-z0-9A-Z\-]+)/?$ /sales/boatlist.php?folder=$1 [NC,L]

So the destination file on the server is:

/sales/boatlist.php?folder=yachts

However, here is my issue.

When this exact category is requested (sales/yachts), the page that is loaded is an apache forbidden reply, and the PHP is not loaded at all; boatlist.php is not called. I deduce from this that there is a file or folder in the directory (therefore escaping the mod_rewrite via the RewriteCond) that is marked as forbidden,
however on the server no file/folder exists with this name and no other mod_rewrites would relate (and shouldn't return 403 forbidden reply even if they did).

I have found server error logs stating:

AH01630: client denied by server configuration: /farm/site/public/sales/yachts

And have obviously researched this error and found it doesn't seem to apply, as my Apache version is 2.4.25 (and has been installed for a long time) and has the current httpd.conf of:

<Directory "/var/www/html">
    Options All
    AllowOverride None
    Require all granted
</Directory>

As far as I can trace, nothing has been updated in the recent days to suddenly cause this issue, but more so, the issue only occurs for a specific url; not for any other URLs, rewritten or not.

http://site.co.uk/sales/dinghies Works.
http://site.co.uk/sales/yachts returns error 403 when no file exists.

What Can I do to further investigate and establish (solve) what's going on here?

(The PHP file the (rewritten) url reaches works perfectly when typed in manually.)

EDIT

Full .htaccess file:

RewriteEngine On
ErrorDocument 404 /index.php?msg=404
ErrorDocument 403 /index.php?msg=403
ErrorDocument 500 /index.php?msg=500
Options -Indexes

#Set asset items to cache for 1 week.
<FilesMatch "\.(gif|jpe?g|png|ico|css|js|swf)$">
     Header set Cache-Control "max-age=1972800, public, must-revalidate"
</FilesMatch>

#force requests to begin with a slash.
RewriteCond  %{REQUEST_URI}  !^$
RewriteCond  %{REQUEST_URI}  !^/
RewriteRule  .*              -    [R=403,L]

#disabled for subdomain
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#if not a file or dir then use as a boat details page variable.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^boats/(\d+)-?([\w-]+)/?$  /sales/boatdetails.php?boatid=$1 [NC,L]

#if not a file or dir then use as a boatlist page variable.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sales/([a-z0-9A-Z\-]+)/?$ /sales/boatlist.php?folder=$1 [NC,L]

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

<Files php.ini>
Require all denied
</Files>

<LimitExcept GET POST HEAD>
    deny  from all
</LimitExcept>
Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132
  • Hi @anubhava . for `/foo/` this outputs `/bar` (as expected). All other paths work as expected with the URL. The `mod_rewrite` doesn't seem to be broadly at fault, as far as I can tell, the issue is too specific. **EDIT**: with the full url this rule does not get met. – Martin Mar 23 '17 at 19:20
  • Ah yes; rewrite engine is turned on automatically in httpd.conf so it doesn't appear in the htaccess. I will add it in for clarity. – Martin Mar 24 '17 at 10:57
  • Ok it seems restart solved your problem.. weird – anubhava Mar 24 '17 at 11:15
  • 1
    @anubhava, thanks for your attention – Martin Mar 24 '17 at 11:50

1 Answers1

0

This morning I ran automatic server update software (updating plugins for the server only) and rebooted Apache.

Apache did not update (so still the same version) but various plugins were updated and after restarting Apache the issue has disappeared.

I still do not know what caused this apparent confusion on the part of Apache.

Martin
  • 22,212
  • 11
  • 70
  • 132