leblanc Posted May 2, 2011 Share Posted May 2, 2011 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. 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] Quote Link to comment https://forums.phpfreaks.com/topic/235368-htaccess-rewriterules-colliding/ Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 Put your rules in reverse order. Quote Link to comment https://forums.phpfreaks.com/topic/235368-htaccess-rewriterules-colliding/#findComment-1209534 Share on other sites More sharing options...
leblanc Posted May 2, 2011 Author Share Posted May 2, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235368-htaccess-rewriterules-colliding/#findComment-1209535 Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235368-htaccess-rewriterules-colliding/#findComment-1209541 Share on other sites More sharing options...
leblanc Posted May 2, 2011 Author Share Posted May 2, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/235368-htaccess-rewriterules-colliding/#findComment-1209543 Share on other sites More sharing options...
leblanc Posted May 2, 2011 Author Share Posted May 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235368-htaccess-rewriterules-colliding/#findComment-1209594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.