ChrisFlynn Posted February 12, 2008 Share Posted February 12, 2008 I guess this is an ordering issue, but no amount of changing the position of [L] seems to work... I'm trying to get the following behaviour on these two conditions: 1) User visits: http://domain.com/foo They see that in their address bar. The page loaded is http://domain.com/page.php?value=foo (To be pedantic, spaces and underscores should be replaced with hyphens in the address bar too - is this possible with [R]? I can parse the value on page.php so that's not an issue... Value should accept hyphens, numbers, letters etc) 2) I also have some 'real' pages which do actually exist (e.g. faq.php, index.php). User visits: http://domain.com/faq (no extension) They see that in their address bar. The page loaded is http://domain.com/faq.php I'm currently achieving the latter with: RewriteRule ^([a-z]+)$ /$1.php, but this isn't working alongside the first RewriteRule ^([A-Za-z0-9-]+)/$ page.php?value=$1 [L] Is there a dynamic way of getting both working, without hard-coding all my 'real' pages in? Quote Link to comment https://forums.phpfreaks.com/topic/90711-newbie-question-rewrites-with-exceptions/ Share on other sites More sharing options...
ChrisFlynn Posted February 15, 2008 Author Share Posted February 15, 2008 I hope I don't sound grumpy, as I know you guys do this for free! However, is there anything I could make more clear? Let me know if there's any confusion; I really appreciate any help! Quote Link to comment https://forums.phpfreaks.com/topic/90711-newbie-question-rewrites-with-exceptions/#findComment-467666 Share on other sites More sharing options...
ChrisFlynn Posted February 20, 2008 Author Share Posted February 20, 2008 I know for a fact MS Server can easily do this (effectively redirect a 404 to /anexceptionfile.php?id=$1); I'm quite surprised it's not simple. Which part of RTFM? Quote Link to comment https://forums.phpfreaks.com/topic/90711-newbie-question-rewrites-with-exceptions/#findComment-472126 Share on other sites More sharing options...
ChrisFlynn Posted February 21, 2008 Author Share Posted February 21, 2008 I got it in the end! # if ($1.php exists) { $1.php } else { search.php?search=$1 } RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^([a-zA-Z]+)$ /$1.php [NC,L] RewriteRule ^([a-zA-Z]+)$ /search.php?search=$1 [NC,L] I'm sure that wasn't worth x hours... oh well Quote Link to comment https://forums.phpfreaks.com/topic/90711-newbie-question-rewrites-with-exceptions/#findComment-472881 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.