2

I have this rewrite rule

RewriteEngine On
RewriteBase /location/
RewriteRule ^(.+)/?$ index.php?franchise=$1

Which is suppose to change this URL

http://example.com/location/kings-lynn

Into this one

http://example.com/location/index.php?franchise=kings-lynn

But instead I am getting this

http://example.com/location/index.php?franchise=index.php

Also, adding a railing slash breaks it. I get index.php page showing but none of the style sheets or javascript are loading.

I'm clearly doing something very wrong but I have no idea what despite spending all day R'ingTFM and many online primers and tutorials and questions on here.

Binarytales
  • 9,468
  • 9
  • 32
  • 38

3 Answers3

5

Your problem is you are redirecting twice.

'location/index.php' matches the regex ^(.+)/?$

You want to possibly use the "if file does not exist" conditional to make it not try mapping a second time.

RewriteEngine on
RewriteBase /location/
RewriteCond %{REQUEST_FILENAME} !-f   # ignore existing files
RewriteCond %{REQUEST_FILENAME} !-d   # ignore existing directories
RewriteRule ^(.+)/?$ index.php?franchise=$1  [L,QSA]

And additonally, theres the [L,QSA] which tries to make it the "last" rule ( Note, this is not entirely obvious how it works ) and append the query string to the query, so that

location/foobar/?baz=quux  ==> index.php?franchise=$1&baz=quux

( i think )

Kent Fredric
  • 56,416
  • 14
  • 107
  • 150
3

It sounds to me as though the rewrite filter is executing twice. Try adding a last flag

RewriteRule ^(.+)/?$ index.php?franchise=$1 [L]
enricopulatzo
  • 4,219
  • 2
  • 17
  • 8
2

Your rule self matches, and therefore it will reference itself.

Douglas Mayle
  • 21,063
  • 9
  • 42
  • 57