ArizonaJohn Posted June 28, 2010 Share Posted June 28, 2010 Hello, I am trying to re-write this: http://www.domain.com/sample/comments/68 Into this: http://www.domain.com/sample/comments/index.php?submissionid=68 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 Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/ Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 Try this... RewriteEngine on RewriteRule ^comments/([0-9]+)?$ /index.php?submissionid=$1 [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078156 Share on other sites More sharing options...
ArizonaJohn Posted June 28, 2010 Author Share Posted June 28, 2010 Hmm... I tried that but it didn't work. Thanks, though. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078200 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078220 Share on other sites More sharing options...
ArizonaJohn Posted June 28, 2010 Author Share Posted June 28, 2010 Okay, thanks. I added the R=302 to .htaccess. How do I use it to diagnose the attempted display page? Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078226 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 Type http://whateveryourdomainis/sample/comments/10 and see what the URL in your address bar changes to. It will hopefully be fairly obviously what is wrong with your rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078229 Share on other sites More sharing options...
ArizonaJohn Posted June 28, 2010 Author Share Posted June 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078231 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078232 Share on other sites More sharing options...
ArizonaJohn Posted June 28, 2010 Author Share Posted June 28, 2010 Oh, okay. The URL did not change. It's still: http://www.domain.com/sample/comments/68 So does that mean that the section below is wrong? ^comments/([0-9]+)?$ Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078234 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078243 Share on other sites More sharing options...
ArizonaJohn Posted June 28, 2010 Author Share Posted June 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078255 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206049-simple-url-re-write-rule-not-working/#findComment-1078260 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.