2

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]
2
  • Could you tell us the url? we can't know which rules apply if we don't know the url.. Commented Dec 29, 2010 at 10:03
  • ikeyless.com/vehicles/Honda/Odyssey - add a / on it and it'll throw a redirect loop error Commented Dec 29, 2010 at 14:29

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

6 Comments

thx for the 404 problem... when I add ? to ^vehicles/?$ it breaks the redirect for vehicles altogether, but works fine on keyfinder.
I have never used or even seen {QUERY_STRING} used with a RewriteRule, only in a RewriteCond, I didn't catch that the first time. It's not needed for your ^vehicles/?$ line anyway. That line redirects to ikeyless.com/vehicle/make/list.php which will load fine without any query_string since that page appears to just generate a list of all vehicles. The other ^vehicles/ lines take care of any specific vehicle requests. So remove {QUERY_STRING} from the line "RewriteRule ^vehicles/$ /vehicle/make/list.php{QUERY_STRING} [L,NC]" and remove "&%{QUERY_STRING}" from all the other lines.
{QUERY_STRING} allows me to accept parameters to that URL.... I'd like to keep that functionality, and it's needed in several places
OK well for the last vehicle line, you need to add &% in front of the {QUERY_STRING} like on your other lines in order to get anything from it. Without the &% it won't return anything, at least not on the tests I ran.
You have 6 RewriteRule lines that check for "vehicles", would those not take care of all your possible requests for a vehicle, or are there some other hidden parameters you need to capture? If so, why not make an additional RewriteRule? In order for the &%{QUERY_STRING} to detect anything, someone would have to type in a url like www.ikeyless.com/vehicles/?key=value which sort of takes away from the purpose of using htaccess to Rewrite the urls so that they look nice.
|
0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.