| 2:57 am on Feb 26, 2010 (gmt 0)|
ok here is basic of what i think u want to do:
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /?cat1=$1&cat2=$2&cat3=$3
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /?cat1=$1&cat2=$2&cat3=$3
if i m not wrong then you are willing to have 50 paramenters like:
so are you really wanna do this?
- Rajendra Pondel
| 8:24 am on Feb 26, 2010 (gmt 0)|
If the code goes in .htaccess, RewriteRule cannot 'see' the leading slash.
Add [L] to the end of every rule.
Don't make the trailing slash optional. Serving the same content at two different URLs is Duplicate Content.
Make the URL without trailing slash the 'real' URL. Set up another rule, a redirect, so that if slash is requested, the redirect (not shown here) removes it.
What is the maximum depth?
Add one more rewrite for each 'level':
RewriteRule ^([^/.]+)$ /?cat1=$1 [L]
RewriteRule ^([^/]+)/([^/.]+)$ /?cat1=$1&cat2=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ /?cat1=$1&cat2=$2&cat3=$3 [L]
| 2:37 pm on Feb 26, 2010 (gmt 0)|
Thank you for the responses. The problem is I don't know what would be the maximum depth, I mean, at least I was trying to create something with N number of arguments.
From your responses I assume there is no way to create such rewrite condition without knowing what would be the maximum depth ?
I guess I limit my class up to certain number submenu.
Thank you very much,
| 3:41 pm on Feb 26, 2010 (gmt 0)|
A single mod_rewrite rule can handle nine parameters, based on the back-reference tokens $1 through $9. It is possible to 'expand' this using multiple rewriteconds and/or rewriterules, but such solutions can be fairly inefficient.
If nine variables proves insufficient, consider passing the "cats" as a single parameter, defined as "cat-list" and separate the category tokens within the "friendly URLs" using hyphens (which are treated as "spaces in words" by most search engines, and which are "safe" to use in a URL-path (they are not required to be URL-encoded).
Alternately, put your cat-list into a client-side cookie, where it will be passed back to the server with each HTTP request. Do be aware that cookies are limited in size as well, though -- 1024 characters(?).
mod_rewrite cannot be viewed as a scripting language; It's meant to be compact and fast for implementing well-defined URL-translation functions ("transcription" would be a more-accurate word), but it is not infinitely-flexible.
| 6:49 pm on Feb 26, 2010 (gmt 0)|
Thank you very much Jim. So let me ask you this question then, if i create a variable called $cats and assign it to something like this $cats = "eu/germany/berlin" will it be recognized as subfolder by search engines once i put this next to my domain? something like below
Thanks in advance,
| 6:52 pm on Feb 26, 2010 (gmt 0)|
I am afraid I can't :)
| 8:53 pm on Feb 26, 2010 (gmt 0)|
As posted, you should use eu-germany-berlin to ease the workload when the friendly URLs are parsed by regex in mod_rewrite.
If you're on Apache 2.x, you might also want to look into using AcceptPathInfo. See the Apache core directives documentation for important details.
| 10:45 pm on Feb 26, 2010 (gmt 0)|
Realisticly, look at the maths.
5 choices of category, at 9 levels of folder, gives 2 million categories.
10 choices of category, at 5 levels of folder, gives 100 000 categories.
20 choices of category, at 9 levels of folder, gives 500 billion categories.
Even a huge site like ODP rarely goes beyond 7 levels.
| 11:59 pm on Feb 26, 2010 (gmt 0)|
Thank you very much for all the responses. I finally finalized the my code, it works fine now.
unfortunately, since my site has been around for three years now, i couldn't use the eu-germany-berlin structure since i've used subfolders for all these years.
so I limit the admin panel to 10 nested categories and i arranged my htaccess accordingly.