themistral Posted January 24, 2008 Share Posted January 24, 2008 Hi guys, I am having a problem in that only the first rule is working. If I comment out the first rule, the second one works fine. Any ideas what might solve it? Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*)\.html$ index.php?page=$1 [L] RewriteRule ^(.*)-(.*)\.html$ shows.php?id=$1&name=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/ Share on other sites More sharing options...
madmax Posted January 24, 2008 Share Posted January 24, 2008 If you intended to chain them then you've marked both rules as the last rule without additional RewriteCond statements If not then the first rule matching means the 2nd won't match after rewrite since the 1st rewrites to index.php and the 2nd matches to *.html Have you tried enabling logging and watching the rewrite process using tail -f ?? Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-447857 Share on other sites More sharing options...
themistral Posted January 24, 2008 Author Share Posted January 24, 2008 I have taken out the [L] after the first rule, but it's still not working correctly. I am still new to this so just to check, my understanding is that the first rule applies to the index.php page only and the second to shows.php. I am trying to sort my server out for error logging - currently getting an internal server error ??? I have used RewriteLog "C:\my\file\path\rewrite.log" RewriteLogLevel 9 I am running this on a local machine so I can mess around with server configs easily if pointed in the right direction! Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-447936 Share on other sites More sharing options...
madmax Posted January 24, 2008 Share Posted January 24, 2008 Since you can have more than one rule in your config each block of rules (up to the [L] - Last) may or may not apply for a given clause or condition Once rewritten subsequent rules are NOT ignored altogether or "skipped" as with a programming language script. Obviously if that were the case you could only have one rule in your config files!. Once a URL is rewritten subsequent rules are checked against the URL to see if they also apply The only way to really understand what is happening is to enable debug logging and watch this stuff in real time using "tail" Some particularly unexpected things often happen with rules - the only way to be sure is check the logs. RewriteEngine On RewriteLogLevel 9 RewriteLog logs/rewrite.log If you posted exactly what you were trying to do someone might be able to script you a ruleset. Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-447999 Share on other sites More sharing options...
themistral Posted January 25, 2008 Author Share Posted January 25, 2008 This is my full code - I use the AddType command to parse php through html files. AddType application/x-httpd-php .php .htm .html Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*)\.html$ index.php?page=$1 RewriteRule ^(.*)-(.*)-by-(.*)\.html$ shows.php?showid=$1&showname=$2&writer=$3 [L] I know that both rules work, it's just that the 2nd one won't run unless I comment the 1st one out - which makes me think I must have an error in my syntax somewhere! What I am trying to achieve is: Rule1 index.php has a query string containing 1 pairing - the value of page should become the new URL with .html added to the end. Rule2 shows.php has a query string containing 3 pairings - the string I want to achieve is showid-showname-by-writer.html. Like I said, rule 2 works if rule 1 is commented out. Still can't seem to get the error reporting working Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-448756 Share on other sites More sharing options...
themistral Posted January 25, 2008 Author Share Posted January 25, 2008 OK, I have reordered the rules putting the 2nd one before the 1st and for some reason the rules are working correctly. Glad to have sorted it, but any ideas as to why it doesn't work the original way round? Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-448859 Share on other sites More sharing options...
madmax Posted January 26, 2008 Share Posted January 26, 2008 It's just one of those things about rewriting that may not immediately be obvious. Subsequent rewrites, circular refs: all part of the joys of Mod_rewrite. Rewriting one rule does not mean others may not apply, nor that they may not apply with the rewritten reference in ways which you didn't expect. As I said - the only way to be sure is to enable logging and see whether what is *actually* happening matches your assumptions Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-449814 Share on other sites More sharing options...
themistral Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks for your help madmax!! I must spend time trying to get that darn error log working! Quote Link to comment https://forums.phpfreaks.com/topic/87518-solved-only-one-rewriterule-working/#findComment-449819 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.