Jump to content

Recommended Posts

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]

 

Link to comment
https://forums.phpfreaks.com/topic/310912-clean-url-not-processing-get-values/
Share on other sites

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.

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 by Nematode128

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.