views:

32

answers:

2

Hello,

I am trying to rewrite URLs ending like (not only exactly equal to) this:

comments/The-Latest-Out-of-Pakistan/68

into URLs ending in this:

comments/index.php?submissionid=68

Below is what I have in the .htaccess file, but it's not working.

RewriteEngine On
RewriteRule ^comments/([A-Za-z0-9-]+)/([0-9]+)?$ comments/index.php?submissionid=$2 [NC,L]

Any idea why it's not working?

Thanks in advance,

John

A: 

I think the only issue is that you've not escaped the hyphen in the character class [A-Za-z0-9-]+, try replacing it with this [A-Za-z0-9\-]+ and see if that works. If not, we can work from there.

Tim Stone
Thanks... I tried it and it still didn't work.
John
What happens instead? You get a 404 or 500 error, or? Also, where is your `.htaccess` file located in relation to your `comments` directory?
Tim Stone
In Chrome, it's just a white page that says "PAGE NOT FOUND" with some other verbiage. I put the .htaccess file in both the comments directory and the one just above it. Do I need to enable mod_rewrite or something?
John
Based on the way your rewrite rule is set up, you only need to put the `.htaccess` file in the directory above the `comments` directory. I *think* the rules should cause an 'Internal Server Error' if `mod_rewrite` isn't enabled, but you can check to be sure with a more obvious 'does-it-work-rule', e.g. `RewriteRule comments/.* http://stackoverflow.com/` if you don't have access to the `http.conf`.
Tim Stone
I see now in Chrome that I am getting a 404 error. I just called my hosting company and they said that mod_rewrite is enabled.
John
Do you have access to the error/access logs in your account? The rewrite rule works fine for me using the setup you've described, so there has to be something else going wrong.
Tim Stone
A: 

I tested it and this one works:

RewriteEngine On
RewriteRule ^comments/([a-zA-Z0-9-]+)/([0-9]+)?$ comments/index.php?id=$2 [NC,L]
Bogdan Constantinescu
Thanks... but when I tried this it still didn't work.
John