Forum Moderators: coopster & phranque

Message Too Old, No Replies

.htaccess rewrite troubles.

look over my syntax real quick?

         

cfe_admin

12:38 am on Dec 14, 2006 (gmt 0)

10+ Year Member



Basically, I'm trying to catch any requests for a URL the matches the following:

[mydomain.com...]

...grab that part number on the end, and redirect them to:

[mydomain.com...]

...plugging in that part number for the keyword. To do so, I'm trying the following lines in my .htaccess file:

RewriteEngine on
RewriteRule cgi-bin/cfcart/cart.cgi\?partno=([0-9]+)$ /cfeproducts/advanced_search_result.html\?keyword=$1&search_in_description=1 [NC,L]

It's not working, any thoughts? Thanks!

jdMorgan

12:45 am on Dec 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are not visible to RewriteRule. You'll need to use a RewriteCond %{QUERY_STRING} directive to check/capture the query data, and back-reference it in the RewriteRule by using %1 through %9, as opposed to $1 through $9.

Break the request at the "?" and match the URL-part in RewriteRule, and the query part in the RewriteCond. The "?" delimiter itself is part of neither.

For more information, see the documents cited in the Apache forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

rocknbil

8:38 pm on Dec 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard! It might be better to approach your problem in the opposite direction, that is, create the URL and direct it to the script, then manage the URL within the script. You can develop keyword rich titles like so:

http://www.example.com/Keyword-Rich-Title

and your mod_rewrite could be

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ cgi-bin/cfcart/cart.cgi [L]

So if the request is not a file, and not a directory, point it to the script. In your script, you have some method of associating the title with the product id. So

/Keyword-Rich-Title

would set

$qs{'partno'} = 50187;

and call up the appropriate page.