Jessica Posted February 12, 2007 Share Posted February 12, 2007 I have the following rules in my htaccess: RewriteRule ^journals([A-Za-z0-9_/]+)$ /journals/base.php [NC] RewriteRule ^quadoo([A-Za-z0-9_/]+)$ /quadoo/base.php [NC] RewriteRule ^scrapbook([A-Za-z0-9_/]+)$ /scrapbook/base.php [NC] RewriteRule ^CMS([A-Za-z0-9_/\-]+)$ /CMS/base.php [NC] I wanted to simplify it, but what I tried didn't work: RewriteRule ^[A-Za-z0-9_]+/([A-Za-z0-9_/\-]+)$ /$1/base.php [NC] Help? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 ^journals([A-Za-z0-9_/]+)$ (and the others) do not require a slash, but ^[A-Za-z0-9_]+/([A-Za-z0-9_/\-]+)$ does. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Author Share Posted February 12, 2007 require it where? I don't see any difference? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 ^journals([A-Za-z0-9_/]+)$ ^ ### BOL journals ### literal ( ### Start capture [A-Za-z0-9_/]+ ### Match one or more of any of these characters; there may not be a forward slash at all! ) ### End capture $ ### EOL ^[A-Za-z0-9_]+/([A-Za-z0-9_/\-]+)$ ^ ### BOL [A-Za-z0-9_]+ ### Match one or more of any of these characters / ### Match a forward slash ( ### Start capture [A-Za-z0-9_/\-]+ ### Match one or more of any of these characters ) ### End capture $ ### EOL Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Author Share Posted February 12, 2007 I still don't get it...it looks to me like the second one should work, but it doesn't... Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 What are the URLs that do and do not work? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Author Share Posted February 12, 2007 If I use: RewriteRule ^([A-Za-z0-9_]+)/([A-Za-z0-9_/\-]+)$ /$1/base.php [NC] None of them work. So I added RewriteRule ^CMS([A-Za-z0-9_/\-]+)$ /CMS/base.php [NC] If you go to http://www.grady.us/CMS/ that works. But if you go to http://www.grady.us/quadoo/, you'll just see the almost-empty index file, not base.php Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 These are failing to match because they do not have data after the slash: ^[A-Za-z0-9_]+/([A-Za-z0-9_/\-]+)$ ^ ### BOL [A-Za-z0-9_]+ ### This is matching "CMS", for example. / ### This is matching the "/". ( ### Start capture [A-Za-z0-9_/\-]+ ### This cannot match anything, therefore failing. ) ### End capture $ ### EOL If you do not require data after the slash, change + to *. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Author Share Posted February 12, 2007 Thanks a ton How come it worked before, when there was a + though? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 Because you weren't matching two sets of data, only one. Review the first comparison I posted line by line, and go through it character by character. The first pattern says "Find 'journals' then one or more characters, which could be a slash"; whereas the second says "Find one or more characters, not including the slash, then a slash, then one or more characters, which could be a slash." That extra step makes all the difference. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Author Share Posted February 12, 2007 Ah, I gotcha. Thanks so much Quote Link to comment 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.