Jump to content

Mod_rewrite Conflict Blowing my Mind Off


zehrila

Recommended Posts

This  script was coded by someone, then i hired someone else to fix the url structure and change it to my liking. The guy tried to fix and achieved the url structure i wanted, but later at this stage i see some conflicts in url structure. I tried reaching the guy who wrote it, but he is no where to be found.

 

okay so here it is.

 

If you go to this page http://mobilephones.pk/cell-phone-themes/nokia-c6-themes.html and scroll down to bottom, and click on page 2, you will land on this page http://mobilephones.pk/cell-phone-themes/nokia-c6-themes-pg-2.php and no database error comes.

 

But when you are on this page,w here mobile name is longer, such as http://mobilephones.pk/cell-phone-themes/nokia-5800-xpressmusic-themes.html and scroll down to bottom and click on page 2, it will show a database error. Amazingly, if if you remove the separator "-" between 5800 and xpressmusic, you will see page loads fine. These files are supposed to be pulled from mobile_themes.php which is echoed on top.

 

Zanus on irc chat helped me a lot nailing down the issue, but he suggested to ask the solution on forum. His suggested its a conflict in .htaccess file line 91 and 92 which are

 

91: RewriteRule cell-phone-themes/(.*)-(.*)-(.*)-themes-pg-(.*).php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3&page=$4 [L]

92: RewriteRule cell-phone-themes/(.*)-(.*)-(.*)-themes.php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3 [L]

 

When we scroll down and click on page 2 for urls with longer mobile names, it instead of hitting mobile_themes.php it tries to fetch data from mobile_tehems_cat.php which i believe is because there is conflict in .htaccess on line 91 and 92.

 

I hope i made some sense, i will highly appreciate if you could find a solution to this.

Link to comment
Share on other sites

 

Zanus on irc chat helped me a lot nailing down the issue, but he suggested to ask the solution on forum. His suggested its a conflict in .htaccess file line 91 and 92 which are

 

91: RewriteRule cell-phone-themes/(.*)-(.*)-(.*)-themes-pg-(.*).php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3&page=$4 [L]

92: RewriteRule cell-phone-themes/(.*)-(.*)-(.*)-themes.php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3 [L]

 

I pointed you to the forums because I suck at mod_rewrite.  Although, I did figure out the problem.. I couldn't figure out a solution.

 

What is wrong with your rewrite, that I pointed out to you on those lines, is that you have the same pattern for two rules, causing variables to be sent to a different script.. causing an SQL error like a chain reaction.

 

This url should go to the OP's mobile_themes.php file.

http://mobilephones.pk/cell-phone-themes/nokia-5800-xpressmusic-themes-pg-2.php

 

but instead, it redirects to mobile_themes_cat.php, because of these lines.

91: RewriteRule cell-phone-themes/(.*)-(.*)-(.*)-themes-pg-(.*).php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3&page=$4 [L]
92: RewriteRule cell-phone-themes/(.*)-(.*)-(.*)-themes.php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3 [L]

 

The OP mentions that there is a database error on longer URLs, but what I tried to explain to him is that it's not the length of the URL, it is the number of characters between dashes.... or better yet, the number of dashes before -themes or -themes-pg.

 

On line 94.. of his htaccess file.

RewriteRule cell-phone-themes/(.*)-(.*)-themes-pg-(.*).php mobile_themes.php?bid=$1&pid=$2&page=$3 [L]

 

I would say the solution to this would be to add another (.*) in there, but that would cause the categories to quit working.

Since you said in IRC that you won't budge from your URL layout for SEO reasons, I'd say your best bet would be to list all possible categories within your regex for mobile_themes_cat.php, like this

92: RewriteRule cell-phone-themes/(.*)-(.*)-(games|cards|food|fruit|beer|squash)-themes.php mobile_themes_cat.php?bid=$1&pid=$2&cat=$3 [L]

Link to comment
Share on other sites

I'm assuming that print_r at the top of the page is the $_GET array. On the first page you linked it only contains 2 items, PID and BID, this being so it can't be the two rules you posted clashing/catching the URL otherwise the array would contain a cat value. The URL is therefore matching a rule earlier in the file. You must have another rule(s) in there that only matches against two capture groups. The two rules you posted cannot clash with each other as one has themes.php as a hard code ending and the other contains themes-pg as hardcoded value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.