jcombs_31 Posted September 6, 2009 Share Posted September 6, 2009 I have a basic directory structure that I want to use with a rewrite rule. Here is the basic directory structure / /info file1.php file2.php /schedules file1.php /staff file2.php info.php schedules.php staff.php So you see I have php files with the same names as the directories. In info.php for example, I will have a switch to include a file inside the info directory. Something like $page = $_GET['page']; switch($page) { case 'file1' include('info/file1.php); break; ... } I want my URL to look like this [mysite.com/info/file1] So, I thought I could write some pretty basic rewrite rule ( mind you I don't really know much of anything about mod_rewrite ) What I have is this RewriteEngine On RewriteCond %{REQUEST_FILENAME} RewriteCond %{REQUEST_FILENAME} RewriteRule ^info/([a-z]+)/?$ info.php?page=$1 [NC,L] But if I go to the url [mysite.com/info/file1] , I get file1, but not included as part of info.php If I simply change the rule to RewriteRule ^somethingelse/([a-z]+)/?$ info.php?page=$1 [NC,L] and then visit [mysite.com/somethingelse/file1] it works fine. So, I'm having a problem with the rewrite matching the directory name. I could just be doing this all wrong, so if anyone can give a good example and explanation of how to accomplish what i want, that would be great Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/ Share on other sites More sharing options...
corbin Posted September 7, 2009 Share Posted September 7, 2009 mysite.com/info/file1 It's strange that that works. assuming "file1" is really a valid value, the problem could be that ([a-z]+) does not match numbers. Guessing that's just a random example though. Aside from that, I doubt this will work, but it might be worth a try: RewriteRule ^info/([a-z]+)/?$ /info.php?page=$1 [NC,L] Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/#findComment-913948 Share on other sites More sharing options...
jcombs_31 Posted September 7, 2009 Author Share Posted September 7, 2009 Yes Corbin, that was a random example, the urls don't actually have numbers. It seems I found the problem. I had to disable multiviews for the rewriting to work correctly. I couldn't figure this out, because my rules worked in a production server, but I just recently set up my testing server and it was giving me problems. This was a good few hours of aggravation. Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/#findComment-914188 Share on other sites More sharing options...
Rebelrebellious Posted September 11, 2009 Share Posted September 11, 2009 You should mark this as solved. I understand that your discovery is that multiviews supercedes mod_rewrite and doesn't even attempt to rewrite the solution it finds. That's good to know. As an aside, would you script be improved by adding a / to the beginning of your regex so? RewriteRule ^/info/([a-z]+)/?$ info.php?page=$1 [NC,L] Or doesn't that work at all? Shouldn''t the request be starting with /? Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/#findComment-916873 Share on other sites More sharing options...
corbin Posted September 11, 2009 Share Posted September 11, 2009 That wouldn't work at all because the / isn't considered part of the URL when matching. Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/#findComment-916932 Share on other sites More sharing options...
Rebelrebellious Posted September 11, 2009 Share Posted September 11, 2009 Thanks. I thought that the / indicated the base path for the website, but based on apache behavior you seem to be correct. Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/#findComment-916951 Share on other sites More sharing options...
corbin Posted September 11, 2009 Share Posted September 11, 2009 It does, but I guess the logic behind it is that the / will always be there so why bother having it. Link to comment https://forums.phpfreaks.com/topic/173344-solved-rewrite-rule-ignoring-directories/#findComment-916956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.