Forum Moderators: phranque

Message Too Old, No Replies

.htaccess mod rewrite [NC] issue/glitch

rewrite rule is working wierd on one rule

         

DailyAmerican

4:25 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



My mod_rewrite in my .htaccess is working for the most part. The problem is that for the category rewrite it only works if I have a capital letter in the word category or if all the letters are capital. Not sure why it won't work if I have category. The business rewrite works fine along with all the other rewrites I have. Just the category one doesn't. Any help would be appreciated. I'm on 1and1 hosting and they don't allow for a log to be generated using my .htaccess.

Works fine:
http://test.example.com/Category/amusement/1/index.html

404 Error:
http://test.examplen.com/category/amusement/1/index.html

Here's my code:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^index.html$ index.php
RewriteRule ^business/(.*)/(.*)/index.html$ index.php?p=business&bid=$2 [NC,L]
RewriteRule ^category/(.*)/(.*)/index.html$ index.php?p=category&cid=$2 [NC,L]
RewriteRule ^certificate/(.*)/(.*)/index.html$ index.php?p=certificate&cert=$2 [NC,L]
RewriteRule ^print/information/(.*)/index.html$ index.php?p=print&data=information&id=$1 [NC,L]
RewriteRule ^print/coupons/(.*)/index.html$ index.php?p=print&data=coupons&id=$1 [NC,L]
RewriteRule ^print/article/(.*)/index.html$ index.php?p=print&data=pages&id=$1 [NC,L]
RewriteRule ^tell-a-friend/information/(.*)/index.html$ index.php?p=tellFriend&data=information&id=$1 [NC,L]
RewriteRule ^tell-a-friend/coupons/(.*)/index.html$ index.php?p=tellFriend&data=coupons&id=$1 [NC,L]
RewriteRule ^tell-a-friend/certificates/(.*)/index.html$ index.php?p=tellFriend&data=certificates&id=$1 [NC,L]
RewriteRule ^contact-us/index.html$ index.php?p=contact [nc,L]
RewriteRule ^catalog/index.html$ index.php?p=catalog [nc,L]
RewriteRule ^articles/(.*)/index.html$ index.php?p=pages&name=$1 [NC,L]
RewriteRule ^certificates/category/(.*)/(.*)/index.html$ index.php?p=certificates&type=category&id=$2 [NC,L]
RewriteRule ^certificates/(.*)/(.*)/index.html$ index.php?p=certificates&type=business&id=$2 [NC,L]
RewriteRule ^certificate/(.*)/(.*)/index.html$ index.php?p=certificate&cert=$2 [NC,L]

[edited by: jdMorgan at 5:53 pm (utc) on Feb. 3, 2010]
[edit reason] Please use example.com only. [/edit]

jdMorgan

6:11 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is not in this code, because it is evident that each rule has an [NC] flag on it, making the rules' pattern-matching completely case-insensitive.

While we strongly recommend against this practice due to duplicate-content-creation concerns, the fact that you've used [NC] pretty much proves that the problem is in configuration code that runs prior to or after this code, or in the index.php script itself.

Note that AcceptPathInfo (on Apache 2.x and above) or MultiViews (on all Apache versions) can confuse this issue -- If you don't use these features, then explicitly turn them off (See Apache-core "Options" and "AcceptPathInfo" directives).

When evaluating hosts in the future, factor the time that you have spent (and will spend) fixing this problem into the calculations of cost. You pretty much get what you pay for, and a host that doesn't provide error logs is close to worthless for anything but amateur "See my cute puppy" sites. For anything more serious, where config tweaks and scripting are required, cheap hosting is the most expensive hosting that you can buy...

To make this reply more useful, note that you can likely improve the performance of your rules above (by a factor of 11, 22, 33, 44, or more) simply by using more-specific regex patterns. For example, replace
 RewriteRule ^category/(.*)/(.*)/index.html$ index.php?p=category&cid=$2 [NC,L] 

with
 RewriteRule ^category/([^/]+)/([^/]+)/index\.html$ index.php?p=category&cid=$2 [NC,L] 


Jim

DailyAmerican

6:25 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



Thank you so much Jim. Disabling the MultiViews fixed the issue.

g1smd

10:12 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have a completely redundant "index.html" part in your URLs. Personally I would remove "index.html" from the URLs published in internal site links, and redirect requests that include "index.html" to new URL without "index.html".

Do change the (.*) patterns in every rule for something more efficient. With the (.*) pattern, some URL requests might require hundreds of 'trial matches' before the correct match is found. Jim's suggested new pattern is very much faster, requiring a single left-to-right parsing of the URL request.

DailyAmerican

3:48 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



Thanks for the tips. I updated the (.*) pattern with Jim's suggested pattern and removed the index.html.