Ben
Ben

Reputation: 62464

.htaccess causing redirect loop

I have a URL on my site that works without a / but when I add a / it says there's a redirect loop... I'm struggling to see the problem here....

Options -indexes
RewriteEngine On
#
#
#php_value output_handler ob_gzhandler
php_value output_handler none
php_flag register_globals off
php_flag safe_mode off

ErrorDocument 404 /404
#
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
#
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

RewriteRule ^battery/([^/]+)$ /browser/product?sku=BATTERY+$1&type=battery
RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)/product([0-9]+)$ /browser/index.php?make=$1&model=$2&id=$3&%{QUERY_STRING} [L,NC]

RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)/([0-9]+)$ /browser/product.php?make=$1&model=$2&year=$3&id=$4&%{QUERY_STRING} [L,NC]

RewriteRule ^vehicles/([^/]+)/([^/]+)/([^/]+)$ /store/product/list.php?make=$1&model=$2&year=$3&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)/([^/]+)$ /vehicle/make/model/year/list.php?make=$1&model=$2&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+)$ /vehicle/make/model/list.php?make=$1&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/$ /vehicle/make/list.php{QUERY_STRING} [L,NC]

RewriteRule ^keyfinder /browser/product?id=1001552 [L,NC]

Upvotes: 2

Views: 1021

Answers (2)

Flyounet
Flyounet

Reputation: 115

Is it possible to have the log of the rewrite engine ?
Add the following lines in your configuration (bellow the RewriteEngine On is enough) :

RewriteLog      logs/rewrite_https.log
RewriteLogLevel 15

I suppose your others logs are in logs/

Upvotes: 0

Craig
Craig

Reputation: 41

I probably would have done some of the regular expression different for the RewriteRule, but it seems to be working accept for that trailing slash. Add /? to the end of each one of your RewriteRules for vehicles, battery & keyfinder. The /? is saying to look for zero or one trailing slash at the end of the line.

Here is an example:

RewriteRule ^vehicles/([^/]+)/([^/]+)/?$ /vehicle/make/model/year/list.php?make=$1&model=$2&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/([^/]+/?)$ /vehicle/make/model/list.php?make=$1&%{QUERY_STRING} [L,NC]
RewriteRule ^vehicles/?$ /vehicle/make/list.php{QUERY_STRING} [L,NC]

The changes above will solve the problem of the redirecting loop caused by the trailing slash, but not the redirecting loop itself. You might have expected your 404 page to show up instead. It didn't work because "ErrorDocument" is wrong. There is no extension for the 404 page.

So again as an example, if your error page is called 404.php, the line needs to look like this...

ErrorDocument 404 /404.php

Hope this helps

Upvotes: 3

Related Questions