Jump to content

Recommended Posts

Hello,

 

I am trying to re-write this:

 

 

Into this:

 

 

Here is what the .htaccess file looks like in both the directory represented by "sample" above and the directory "comments":

 

RewriteEngine on
RewriteRule ^comments/([0-9]+)?$ index.php?submissionid=$1 [NC,L]

 

The first URL (http://www.domain.com/sample/comments/68) goes to a 404 error. I have checked, and mod_rewrite appears to be enabled. Also, when I manually enter the second URL, the correct page pulls up.

 

Any idea why my the URL re-write is not working?

 

Thanks in advance,

 

John

Link to comment
https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/
Share on other sites

Well the 404 indicates file not found. Add in the R=302 flag to diagnose what page it is actually trying to display and work from there.

 

RewriteEngine on
RewriteRule ^comments/([0-9]+)?$ /index.php?submissionid=$1 [NC,L,R=302]

I did that and it's still giving the same 404 error as before:

 

PAGE NOT FOUND

We cannot locate the page you're looking for. Please check the address and make sure all letters are lowercased with no spaces. You may also move to a different page by using the links in the menu bar above.

Yes, because the page can't be found, I didn't expect anything different As I stated the point was, what did the URL change to in the address bar? If it didn't change at all the the first part of your rule is wrong, if it did then the second part is wrong.

Yes, it means that is not matching the actual URL. Not the easiest thing in the world to troubleshoot. Try placing just this in a .htaccess file.

 

RewriteEngine On
RewriteCond %{REQUEST_URI} !hmm.php
RewriteRule ^(.*)$ /hmm.php?url=$1 [R=302,L]

 

And visit http://www.domain.com/sample/comments/68, see what comes up in the address bar.

When I do that, the URL is

http://www.domain.com/hmm.php?url=68

.

 

This URL shows up when I put the .htaccess file in the comments subdirectory. 

 

Does that provide any clues?  I think my problem may have to do with trying to do this re-write in a subdirectory. 

Yes, I didn't realise your .htaccess file was within the comments directory, I thought you had it in the sample directory. The URL you are matching against in a RewriteRule is only relative to the position of the .htaccess file so although the REQUEST_URI is /sample/comments/68, you are only actually matching against the 68 part if your .htaccess file is in your comments directory. Either move the .htaccess file up a directory into the sample folder or remove the 'comments/' part from the RewriteRule.

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.