Forum Moderators: phranque

Message Too Old, No Replies

Rewrite for short URL searches?

         

IsItFast

10:51 pm on Dec 1, 2009 (gmt 0)

10+ Year Member



I'll try to make this short as possible. I'm moving from an old cart to a new cart. The new cart isn't live yet so I'm just wanting to get the new cart to have similar links as my old cart but the Rewrite rule I am using isn't working properly.

Example:

www.example.com/oldcart/mouse will show search results for "mouse"

I need to get similar results with my new cart but using Rewrite generators aren't producing the results I need.

New site example should be:

www.example.com/newcart/mouse and give results for "mouse" if searched for. But is just listing my Category called "mouse". I tried two totally different Rewrite rules but they both gave similar results. Another example is:

http://www.example.com/shop/Bear It is in the "Bear" subcategory. But if you do a search for "bear" totally different results show up since not all bear decals are in the bear category.

# Enable Rewrite Engine
RewriteEngine on

#Create friendly URL
RewriteRule ^shop/mouse$ shop/index.php?subcats=Y&type=extended&status=A&pshort=Y&pfull=Y&pname=Y&pkeywords=Y&cid=0&q=mouse&x=0&y=0&dispatch=products.search [L]

Of coarse I am a total newb to this...and trying to search for this type of question was pulling up all kinds of unrelated results.

[edited by: jdMorgan at 2:12 pm (utc) on Dec. 2, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:25 pm on Dec 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code looks basically OK, but since we don't know what each of your query string parameters means, it's not possible to analyze a search results problem by just looking a the code. Please describe the query string parameters, and whether any of them might affect the problem of seeing a category listing when you expect to see a product listing in the search results.

It may be simply that, your site design being new, it has not yet been fully-indexed; Category pages, usually appearing 'higher' in the site's internal linking structure, will be spidered and ranked first, and unless the search is specific to words that appear only on product pages, it's entirely natural that a category page may out-rank a product page.

Jim

IsItFast

5:33 pm on Dec 2, 2009 (gmt 0)

10+ Year Member



Let me further explain. When I am using the term "search" I am referring to the search function on my site; not the search engines themselves.

So if I type into my url www.example.com/shop/bear should generate a search of my entire site for the word bear. This is how my old cart functioned using a rewrite.

The search string I used to generate the code shows all products on my site listing the word "bear". But the rewrite only goes to my category called "bear". That key term has to be an exact match to the category. The term "bear" works since I have a category called that. But example www.example.com/shop/dog does not work as my category for "dog" is "dog decals". I am not wanting the rewrite to just look for categories....it should search for the keyword in categories, product name, search words, etc. Here is the search string used.

http://example.com/shop/index.php?type=extended&match=any&q=bear&pname=N&pname=Y&pshort=Y&pfull=Y&pkeywords=Y&cid=0&category_name=All+categories&pcode=&price_from=&price_to=&weight_from=&weight_to=&dispatch[products.search]=Search

Oh, and sorry for including a real link to my site in the previous post.

jdMorgan

6:52 pm on Dec 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This problem must be addressed in your site search script then, because the information that 'bear' items might be located in 'dog' categories is completely lost in your new friendly-URL-scheme. Since mod_rewrite works only on incoming URL requests, there is nothing it can do to 'recover' that lost information (I presume it used to be present in the query string?).

At any rate, this search problem is due to the site's new architecture, and not to any problem specific to mod_rewrite. The search script will have to be modified to 'comprehend' this new architecture, and to issue searches for all categories. This may mean issuing consecutive searches using all possible 'friendly' category URLs, or (a better option) it may mean defining an additional friendly-URL-space such as example.com/search/<keyword> (where <keyword> is "bear" in our current example) that maps to your dynamic script query space using a 'category' parameter of 'all' or 'search' -- I'm just guessing here and throwing out some ideas, as I certainly don't know all the details of how your site works.

Jim

IsItFast

7:07 pm on Dec 2, 2009 (gmt 0)

10+ Year Member



Once again I have confused you in my post (sorry). "Dog" results don't appear in "bear" searches.....I was just using that as an example for a different issue that may have helped give a clue to what was going on in the string. I was simply stating that www.example.com/shop/dog won't give any results of my dog category because the category name is "Dog Decals". Since "dog" doesn't match the search term exactly (it has "decals" after it) a 404 page error appear.

www.example.com/shop/bear gives results of the bear category ONLY. But I want it to search the entire site for the word bear; not just in the bear category.

jdMorgan

8:05 pm on Dec 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



www.example.com/shop/bear gives results of the bear category ONLY. But I want it to search the entire site for the word bear; not just in the bear category.

And that is what I directly addressed in my post above. I don't see that your search problem has anything to do with the type of rule you posted above, and it isn't because I don't understand what you've said or don't understand your rule. It's that your rule is for "shop" and and contains only the product "mouse", and now you're asking about the operation of your site search. If your site search now also uses 'friendly URLs' then those friendly URLs must contain all the information needed to do a cross-category search, and that's all I can really say about searches given what I read here.

Let me address your rule directly.. Maybe that will help, though I'm not sure it will:


#Create friendly URL
RewriteRule ^shop/mouse$ shop/index.php?subcats=Y&type=extended&status=A&pshort=Y&pfull=Y&pname=Y&pkeywords=Y&cid=0&q=mouse&x=0&y=0&dispatch=products.search [L]

This rule *does not* create a URL. In fact, mod_rewrite cannot create or change URLs at all. URLs are 'created' by the act of publishing them in links on Web pages. mod_rewrite accepts incoming client (e.g browser) requests for URLs as those requests arrive at your server, and in basic terms, can do one of two things with them:

It can redirect them to a different URL, telling the client "Please ask for what you wanted again at this different URL," and ending the current HTTP transaction (The client must start a new HTTP transaction by asking for the URL we just gave it -- if it elects to do so).

Alternately, mod_rewrite can simply re-map the incoming URL request to a different server filepath than that to which it would be resolved if no mod_rewrite code were present. And that is what you are doing with your rule here.

Instead of letting the server look at the real server directory "/shop" for a real file named "mouse", your rule takes that URL request, re-formats it, and passes it to your script as "shop/index.php?subcats=Y&type=extended&status=A&pshort=Y&pfull=Y&pname=Y&pkeywords=Y&cid=0&q=mouse&x=0&y=0&dispatch=products.search"

The URL requested by the browser is "example.com/shop/mouse", the script filepath is "/shop/index.php", and the query string parameters are "subcats=Y&type=extended&status=A&pshort=Y&pfull=Y&pname=Y&pkeywords=Y&cid=0&q=mouse&x=0&y=0&dispatch=products.search"

I don't know if that will help, but the terminology in both this post and my previous posts is precise; Distinguishing between URLs and filepaths is essential, as is an understanding of when mod_rewrite acts, and what it can do.

Jim

IsItFast

10:41 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



Thanks for the help Jim. As stated in my first post (I am a newb so) I totally have no idea how these work. But I created one many years ago with the help of my shopping cart community. It just worked right off the bat so I never really tried to learn "how" it worked. I thought this would be as simple with my new cart but apparently not.

I used a couple of mod-rewrite generators to try and generate the proper rules for the code above. One didn't work at all. But 2 gave the same results I am having even though the rewrite rules were totally different. I'm not sure why the one I have in the example above works for other search terms besides "mouse" but it does. example.com/shop/mouse gives results for the mouse category. example.com/shop/bear give results in the bear category, etc. In any case both rules seem to be forcing the category in the results...not just a general query for the term. I thought an expert just may be able to look at the code and know instantly what the problem was but I guess it goes deeper than that.

My brain is scrambled trying to decipher all of this so I'm gonna take a break.

IsItFast

10:55 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



And just so there isn't any confusion on the example rule that has the term "mouse" in it. Here is the other rules that gives the same (wrong) results:

-----

RewriteRule ^([^/]*)$ /shop/index.php?subcats=Y&type=extended&status=A&pshort=Y&pfull=Y&pname=Y&pkeywords=Y&cid=0&q=$1&x=0&y=0&dispatch=products.search [L]

jdMorgan

4:33 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your site and problem are complex enough that there is essentially no chance that we can hand you a correct solution all in one go. Also, we're a discussion forum here, not a free coding service. So you'll need to either commit to studying up on Apache URL rewriting (See the links in our Charter and the threads in our library), hire someone to work this out for you (I strongly suggest that you hire someone in your town/city to avoid both technical and contractual problems), or forgo the use of mod_rewrite... It's simply dangerous to use it without understanding it -- One typo or a tiny logic problem can sink your site in search, and possibly put you out of business.

Jim