2

I have a series of rules configured in my apache2 conf file that look like this:

RewriteEngine On

LogLevel alert rewrite:trace3

RewriteCond %{HTTP:Accept} text/xml [NC]
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.xml

RewriteCond %{HTTP:Accept} text/json [NC]
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.json

These perform the following tasks:

1) If the URL called has no extension and a header has been passed in of "text/xml" then append .xml

2) If the URL called has no extension and a header has been passed in of "text/json" then append .json

This works fine, except in a specific scenario:

If I have a folder containing the following:

2016.xml
2016.json
2016    <-(A sub folder)

The user calls http://example.com/foo/bar/2016 and has the Accept header set to "text/json" or "text/xml"

In this case the rules do not fire and a directory listing of the 2016 folder is returned instead of the appropriate file.

Any way I can configure to make it return 2016.xml or 2016.json in this scenario?

Thanks!

A Sims
  • 107
  • 1
  • 10

0 Answers0