Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite Help

         

Makaveli

3:24 am on Mar 29, 2006 (gmt 0)

10+ Year Member



Hello,

I was hoping somebody can help me. This is the mod rewrite for my auction site. It works great, however I was wondering if it's possible to remove the "Category/" part before each url.

Is this possible to do this with the rules below? I have tried but was unsuccessful. Can someone help?

# Browse auction
RewriteRule ^Category/.*/[^/]+\_([0-9]+).html+$ index.php?a=1002&b=$1

# Browse auctions by category
RewriteRule ^Category/([^/]+/?[^/]+)/$ index.php?a=1005&b=$1&c=
RewriteRule ^Category/([^/]+/?[^/]+)/\?Browse=([^&]+)$ index.php?a=1005&b=$1&c=$2
RewriteRule ^Category/.*((images¦css)/[^.]+\.[a-z]+)$ $1
RewriteRule ^Category/.*/([^/]+\.[a-z]+)$ $1

Thanks in advance!

jdMorgan

1:49 pm on Mar 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends. Are you trying to eliminate the "Category" in the requested URL (the one indexed by search engines), or in the substitution -- the server filepath associated with that requested URL?

If the former, then you need to consider how you intend to tell mod_rewrite that a URL should or should not be rewritten. In other words, if you remove the "Category" path from the URL, then mod_rewrite will rewrite *all* URLs because it has no way to identify URLs that should not be rewritten. Even in this case, it is usually possible to shorten the unique-identifier part of the URL, say to "Cat" instead of "Category."

Another approach, though far less efficient, is to rewrite only those URLs that do not exist as 'real' files or directories.

In other words, you must make the rewrite/no-rewrite decision based on characteristics of the URL -- The (sub)directory path, the filetype, the presence or absense of other unique characters, strings, or classes of characters, or whether the filepath exists or does not exist. But you have to give mod_rewrite something to make this decision.

Jim

Makaveli

3:20 pm on Mar 29, 2006 (gmt 0)

10+ Year Member



Hey jdMorgan,

Thanks for your reply.

Basically the urls that my site used to show was this [mysite.com...]

With the mod rewrite the urls are now like this [mysite.com...]

I was just hoping there is a way to remove the "Category" part of the url so that the urls would read like this [mysite.com...]

I have tried changing the wording of the word Category to somethings else (example cat) and it worked, but I can't seem to get rid of that entire section. I'm not that good with Mod Rewrite and I was hoping somebody would have a better idea.

Thanks

jdMorgan

11:14 pm on Mar 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are two pieces to this puzzle:

First, you changed the URLs on your pages from www.example.com/index.php?a=1005&b=342&c= to
www.example.com/Category/Cell_Phones/

This changed the URLs that your visitors see, and it also changed the URLs listed in search engines.

But these URLs no longer pointed to valid pages on your site. So, you used mod_rewrite to 'map' or 'forward' those new URLs to the index.php file, with the product type passed as a variable, so that index.php can generate the correct requested page content.

That's just to be clear on what mod_rewrite does, because mod_rewrite does not change the links on your pages, it only changes the file associated with a requested URL.

With that made clear, the only remaining problem is that if you eliminate the "/Category" part of the URLs on your pages, you will need a mod_rewrite rule for each and every product in that category. That might mean 20 rules, which is reasonable if not optimal, or it could mean hundreds of rules to map each product to index.php with the correct product ID variable. Hundreds of rewrite rules will be difficult to write, difficult to maintain, and could have a very bad effect on your server's performance if you run a high-traffic site. I do not recommend this approach.

Hopefully, this information will help explain my first post above.

Jim