Forum Moderators: phranque
www.example.com/product/category/type
and have it pull up
www.example.com/product.php?cat=category&type=type.
I understand the basic concept, my problem is what I think is me creating a loop that I don't know how to get around. My .htacess code is:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^product/(.*)/(.*)$ product.php.cfm?cat=$1&type=$2 [L]
Unfortunately, if I enter
www.example.com/product/category/type
it returns a 500 internal server error, but if I change my .htaccess file to read
RewriteRule ^products/(.*)/(.*)$ product.php.cfm?cat=$1&type=$2 [L]
and enter the new URL, it pulls up the page fine. I'm guessing it's choking because product (singular) in the file keeps getting rechecked. How do I get around this? Thanks!
RewriteRule ^date-ideas/(.*)/(.*)$ date-ideas.cfm?cat=$1&dID=$2 [L]
seems to now match and replace for all of my other pages (ie a link to fun-date-ideas.cfm is now date-ideas/category/fun-date-ideas.cfm)
Maybe my original question should have been how do I get mod_rewrite to ONLY match a term like "date-ideas" and disregard "fun-date-ideas", "date-ideas.cfm", etc? Or am I still confused? Boy this is a lot more difficult than it seems like it should be.
RewriteRule ^date-ideas/(.*)/(.*)$ date-ideas.cfm?cat=$1&dID=$2 [L]
Therefore, it is not this rule that is causing the problem unless that is not the exact rule or the exact requested URL-path (the link on your page).
The only thing I see wrong with your rule is a "sloppy" pattern that is also very inefficient. Avoid the use of ".*" sub-patterns in order to prevent unexpected results -- A sub-pattern of ".*" matches anything, nothing (blank), and everything. Putting more than one is a pattern is also hugely inefficient, causing dozens, hundreds, or even thousands of 'back-off-and-retry' matching attempts. Too many of these can kill a busy server. (If you see such a multiple-".*" pattern recommended in a forum, run away.)
Instead, try a much more specific pattern such as
RewriteRule ^date-ideas/([^/]+)/([^/]+)$ date-ideas.cfm?cat=$1&dID=$2 [L] This matches all characters from after the first slash up to the second slash into $1, and everything after that slash into $2, but will not match a requested URL if it contains a third slash. You could make it even more specific, excluding URL-paths with a filetype (indicated by a period) in the final URL-path-part, by also excluding periods in the second subpattern:
RewriteRule ^date-ideas/([^/]+)/([^./]+)$ date-ideas.cfm?cat=$1&dID=$2 [L] If these patterns are not clear, take a look at the resources cited in our Forum Charter, especially the regular-expressions tutorial.
Jim
<snip> the links in the nav menu on the left are fine, but if you then pull up a page with the pattern I'd like to use, ie http://www.example.com/date-ideas/romantic/page the nav links all get mucked-up.
[edited by: jdMorgan at 1:46 am (utc) on June 1, 2009]
[edit reason] No URLs, please. See Terms of Service. [/edit]
It may help to clarify this problem if you understand that it is the client (e.g. the browser or robot) that resolves relative links into the full URL that it must request. If you use page-relative links, the browser takes the URL in its address bar, strips off the "file" (if present) leaving the full directory path, and then adds your relative link to that. By using 'fake directories' as your links, you are telling the browser to resolve relative links based on those directory paths.
Jim
[edited by: jdMorgan at 2:12 am (utc) on June 1, 2009]