Reply
Mod_Rewrite Dilema..
Old 12-23-2004, 10:25 PM Mod_Rewrite Dilema..
Brian07002's Avatar
Webmaster Talker

Posts: 520
Name: Brian
Location: United States
Hi,

I am using the webmaster-toolkit online generator to make a couple of rules for my website, but I am having a bit of a problem...

1.
Quote:
Options +FollowSymLinks
RewriteEngine on
RewriteRule index/(.*)/(.*)/(.*)/(.*)/$ /shop/index.php?$1=$2&$3=$4
if I input the above code into my .htaccess file, all works fine and dandy, the urls will become 'search engine friendly', but if I go and add a couple of additional rules with the above one included in the .htaccess file, none of the rules work...

Here are the other two rules:

2.
Quote:
Options +FollowSymLinks
RewriteEngine on
RewriteRule index/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ /shop/index.php?$1=$2&$3=$4&$5=$6
3.
Quote:
Options +FollowSymLinks
RewriteEngine on
RewriteRule index/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ /shop/index.php?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10
How do I add the additional rules into one file so it will work?

FYI: The rules have this effect:

Rule 1: Make all category pages search engine friendly
Rule 2: Make all sub-category pages search engine friendly
Rule 3: Make all product pages search engine friendly

Thank you for your support!
-Brian
__________________
Brian
TMS BBS: 201-471-2205
Open Friday thru Sunday Eastern Time (US & Canada)
Brian07002 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-24-2005, 04:21 AM
fambi's Avatar
Ultra Talker

Posts: 339
Hi there.

If you havent solved your problem, i've also been through this.

Firstly, I found that mod rewrite happily accepted 9 variables, but no more.

To solve this, we have to understand how RewriteRules work:

Each (.*) represents one of those $ variables. So, if you know for sure what the variable names are going to be (e.g. $category, $subcategory etc.), you could take them out of the list of $1, $2 variables like this:

Rather than : RewriteRule index/(.*)/(.*)/(.*)/(.*)/$ /shop/index.php?$1=$2&$3=$4

Put this : RewriteRule index/category/(.*)/subcategory(.*)/$ /shop/index.php?category=$1&subcategory=$2

You can see that in action here : http://www.tm4b.com/useful_links/development_groups.php

My mod RewriteRule looks like this:RewriteRule useful_links/(.*).php$ /useful_links.php?class=$1

Although it originally looked like this: useful_links/(.*)-(.*).php$ /useful_links.php?$1=$2

This should half the number of $ in the RewriteRule.



Secondly, if RewriteRules share the same variables, they'll conflict with each other. So if you are calling the second of your described RewriteRules, it will think you are calling the first (for example).

The solution to that is to have only 1 RewriteRule and declare all the possible variable names in it, even if you leave the actual variables blank.

For example, if a user is looking a category page, the url should still declare the sub-category variable and the product variable, and just leave them blank.

So rather than : /shop/index.php?category=1

The url should read : /shop/index.php?category=1&subcategory=&product=

Hope it all makes sense.
__________________
Sending sms from a website or application is easy!
Read this great tutorial that uses our bulk sms gateway.

Last edited by fambi : 01-24-2005 at 04:59 AM. Reason: Found an error in my code
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Mod_Rewrite Dilema..
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.37458 seconds with 12 queries