4
votes

A request to http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites

gets redirected as follows:

> Request URL:http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites
> Request Method:GET
> Status Code:301 Moved Permanently

Response headers:

> HTTP/1.1 301 Moved Permanently Date: Thu, 06 Sep 2012 14:32:41 GMT
> Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4
> mod_perl/2.0.4 Perl/v5.10.1 Location:
> http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites/
> Content-Length: 417 Keep-Alive: timeout=5, max=100 Connection:
> Keep-Alive Content-Type: text/html; charset=iso-8859-1

I am not sure what causes this redirect.

I have the following .htaccess in folder c:\xampp\htdocs\SAMPLE-CODES\backbone-mysql-reading-json\:

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
1
Are there any other .htaccess files that could be involved? Maybe @ the root of the website? The one shown didn't do this redirect.HeatfanJohn
No other .htaccess file in subfolders. I have a VirtualHost config in the httpd.conf. Could that have an impact?Timothée HENRY
I am using Slim PHP framework, and I suspect now that I am getting this: dev.slimframework.com/phpdocs/classes/…Timothée HENRY

1 Answers

6
votes

This is probably because of the mod_dir and the DirectorySlash directive that's doing the redirect. With it on, when apache looks at a URI and thinks it's accessing a directory, and is missing the trailing slash, it 301 redirects to the URI with the trailing slash. It's always turned on by default because there's an information disclosure security issue if you have it turned off. But if you are routing everything through an index.php script, it may not even matter and you can turn it off by simply adding DirectorySlash Off in your htaccess file (and turn it on for directories that you can access directory, like css or js or images, etc.