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 Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment 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 /? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. 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.