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? Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/ 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. Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182472 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? Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182473 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 Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182475 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... Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182476 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? Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182477 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 Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182481 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 *. Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182482 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? Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182485 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. Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182491 Share on other sites More sharing options...
Jessica Posted February 12, 2007 Author Share Posted February 12, 2007 Ah, I gotcha. Thanks so much Link to comment https://forums.phpfreaks.com/topic/38103-regex-in-htaccess-folder-structure/#findComment-182494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.