Jump to content

htaccess RewriteRules Colliding


leblanc

Recommended Posts

Hello. Having a real brain teaser here. Everything works fine like it should until I get to mysite.com/index.php?page=XXX&parent_url=XXX&child_url=XXX Then I get this error

 

Warning: include(browse/12-oclock-bars/cbr-600-f4i.php) [function.include]: failed to open stream: No such file or directory in /home/bray/public_html/index.php on line 167

 

Warning: include() [function.include]: Failed opening 'browse/12-oclock-bars/cbr-600-f4i.php' for inclusion (include_path='.:/usr/lib/php') in /home/bray/public_html/index.php on line 167

 

But the first two lines are working fine. Why would the 3rd line not work for my site. But if I comment out the first two lines, than the third line works.... I'm so confused.

 

Here is my HTACCESS file. Any help would be greatly appreciated.  :shrug:

 

RewriteCond %{HTTP_HOST} ^mysite.com [NC] 
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]


RewriteCond %{REQUEST_URI} !^index.php?
RewriteRule ^(.*)/$ /index.php?page=$1 [L,NC]
RewriteRule ^(.*)/(.*)/$ /index.php?page=$1&parent_url=$2 [L,NC]
RewriteRule ^(.*)/(.*)/(.*)/$ /index.php?page=$1&parent_url=$2&child_url=$3 [L,NC]

Link to comment
Share on other sites

wildteen88,

 

Errr, I feel stupid. I feel like I tried that and it didn't work, but it is working now.

Thank you so much for your advice.

 

While where on topic, is it better to place the (.*), or the ([^/\.]+).... whats the difference?

Link to comment
Share on other sites

I'm not a regex expert but I believe (.*) is greedy. Whereas ([^/\.]+) is lazy. I maybe wrong on the latter.

 

Whenever I use regex I prefer to use character classes eg I use /([a-z])+/ if I'm only searching for letters in a segment of the url, or /([a-z0-9])+/ if a segment of the url can contain letters and numbers etc.

Link to comment
Share on other sites

Great, Now it won't work again with another problem.

 

Here, Line 3 won't work, but all the others do, If I change its position up or down, the others stop working.

 

RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ /index.php?page=$1&parent_url=$2&child_url=$3&product=$4 [L,NC]

RewriteRule ^(.*)/(.*)/(.*)/$ /index.php?page=$1&parent_url=$2&child_url=$3 [L,NC]

RewriteRule ^(.*)/(.*)/(.*)/$ /index.php?page=$1&parent_url=$2&product=$3 [L,NC]          <---------------

RewriteRule ^(.*)/(.*)/$ /index.php?page=$1&parent_url=$2 [L,NC]

RewriteRule ^(.*)/$ /index.php?page=$1 [L,NC]

Link to comment
Share on other sites

Solved at the simplest method

 

RewriteCond %{REQUEST_URI} !^index.php?

RewriteRule ^product/(.*)/(.*)/(.*)/$ /index.php?page=product&parent_url=$1&child_url=$2&product=$3 [L,NC]

RewriteRule ^product/(.*)/(.*)/$ /index.php?page=product&parent_url=$1&product=$2 [L,NC]

RewriteRule ^browse/(.*)/(.*)/$ /index.php?page=browse&parent_url=$1&child_url=$2 [L,NC]

RewriteRule ^browse/(.*)/$ /index.php?page=browse&parent_url=$1 [L,NC]

RewriteRule ^(.*)/$ /index.php?page=$1 [L,NC]

 

Had to give them all identifiers  <-- Thanks to clmarquart and wildteen for all the help.

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.