Reputation: 9001
Sample Code
Here is a sample of my .htaccess
file:
RewriteEngine On
RewriteRule ^home/?$ index.php?intro=true [L]
RewriteRule ^home/([^/]*)$ index.php?location=$1&intro=true [L]
RewriteRule ^wedding/?$ wedding.php [L]
RewriteRule ^wedding/([^/]*)$ wedding.php?location=$1 [L]
And here is some sample code that is featured on both the index.php
and wedding.php
page:
index.php:
if(!$_GET["location"]) { $location = "London"; } else { $location = ucwords($_GET["location"]); }
[....]
<h1>Ben Pearl, <?php echo $location; ?> Magician</h1>
wedding.php:
if(!$_GET["location"]) { $location = "London"; } else { $location = ucwords($_GET["location"]); }
....
<h1><?php echo $location; ?> Wedding Magician</h1>
What is supposed to happen
The $location
string should be effected by the $_GET
value 'location
'.
What is happening
The rewrite is working fine on index.php
; if a user goes to example.com/home/place, $location
is replaced by place
.
However, on every other page (including the page with script pasted above), the string is replaced by "london", implying that the page hasn't received the $_GET
data and the rewrite rule is not working correctly.
What's stranger is that the exact same code, unaltered, worked fine on my localhost
.
Upvotes: 2
Views: 133
Reputation: 143886
Try turning off Multiviews
, which turns on mod_negotiation's "fuzzy" request URI to file mapping. When mod_negotiation sees /wedding/
and then it sees that there's a file /wedding.php
, it'll kick in and send the request directly there, completely bypassing mod_rewrite and your rules.
On top of your htaccess file, add:
Options -Multiviews
That may also explain why it works for the rewrite to index.php
, since /home
doesn't look much like /index.php
(whereas if you had a home.php
, mod_negotiation would try to map to that instead).
Upvotes: 2