Nematode128 Posted June 10, 2020 Share Posted June 10, 2020 I've been messing around with clean urls in php and I've been having some trouble. I'm working on a private messaging system and when I go to "sitename.com/mail/view.php?page=inbox" it correctly displays the users inbox messages but when I put "sitename.com/mail/view/inbox/" it just displays the page like the GET value isn't set. Why is that? this is the HTACCESS file for clean url RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^view/([a-z]) view.php?page=$1 [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/ Share on other sites More sharing options...
Nematode128 Posted June 10, 2020 Author Share Posted June 10, 2020 My php is something like this to display the inbox <?php $page = $_GET['page']; if ($page == 'inbox') { echo "Inbox"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/#findComment-1578785 Share on other sites More sharing options...
requinix Posted June 10, 2020 Share Posted June 10, 2020 It seems like you're mixing two different URL rewriting schemes together: the normal version where you look for files that don't exist, and an alternative version where you automatically add a .php extension. Use one or the another. Not both. In your case you are not adding the extension automatically because the URL is like /view/inbox and you don't have a /view/inbox.php script. So replace that second RewriteCond with one that ensures the REQUEST_FILENAME is not an existing file. Then you'll have another problem. Make your script print out $page and you should be able to see what's wrong fairly quickly. Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/#findComment-1578787 Share on other sites More sharing options...
Nematode128 Posted June 10, 2020 Author Share Posted June 10, 2020 (edited) 29 minutes ago, requinix said: It seems like you're mixing two different URL rewriting schemes together: the normal version where you look for files that don't exist, and an alternative version where you automatically add a .php extension. Use one or the another. Not both. In your case you are not adding the extension automatically because the URL is like /view/inbox and you don't have a /view/inbox.php script. So replace that second RewriteCond with one that ensures the REQUEST_FILENAME is not an existing file. Then you'll have another problem. Make your script print out $page and you should be able to see what's wrong fairly quickly. I printed out page with what I currently have and it printed just "i" I'm really new to HT access so can you provide some references on how I'd rewrite it? I followed this tutorial: https://www.youtube.com/watch?v=zJxCq6D14eM and from the way they made it sound view/inbox should have been processed like view.php?page=inbox based off the example they used Edited June 10, 2020 by Nematode128 Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/#findComment-1578788 Share on other sites More sharing options...
requinix Posted June 10, 2020 Share Posted June 10, 2020 I'm not prepared to go through 20 minutes of video to find what you're talking about. RewriteCond %{REQUEST_FILENAME} !-d That makes sure the next RewriteRule only affects URLs that weren't for a directory. RewriteCond %{REQUEST_FILENAME}\.php -f That makes sure that the next RewriteRule only affects URLs that exist if you were to take the path and add a .php extension. /view/inbox is not a directory (good) but /view/inbox.php does not exist. So there will be no rewriting. That second RewriteCond is the problem. Check the docs to see what it needs to look like so that it instead makes sure to only affect URLs that aren't for a file. Hint: it almost identical to the one about directories. When that's fixed, spend a moment to learn about regular expressions in Apache's URL rewriting, then take a closer look at what your RewriteRule is doing. Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/#findComment-1578790 Share on other sites More sharing options...
kicken Posted June 10, 2020 Share Posted June 10, 2020 7 minutes ago, Nematode128 said: I followed this tutorial: https://www.youtube.com/watch?v=zJxCq6D14eM and from the way they made it sound view/inbox should have been processed like view.php?page=inbox based off the example they used His explanation of regular expressions and the first argument of RewriteRule is pretty poor IMO, but you did miss one part of it at 12:20. Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/#findComment-1578791 Share on other sites More sharing options...
Nematode128 Posted June 10, 2020 Author Share Posted June 10, 2020 13 minutes ago, kicken said: His explanation of regular expressions and the first argument of RewriteRule is pretty poor IMO, but you did miss one part of it at 12:20. Gotcha that seems to have fixed it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/#findComment-1578792 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.