0

My URL looks like this:

http://127.0.0.1/website/comments.php?topic_id=16

I want to make it look like this:

http://127.0.0.1/website/comments/my-news-article/16.php

I have applied this

RewriteEngine on
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2

I have also turned on Rewrite_module in Apache.

But it's not working.

2
  • where does my-news-article come from? Is it part of the original URL? Commented Sep 13, 2012 at 21:05
  • not correctly specified there are parts that where needed to solve the problem you wanna rewrite two parameters but you are GET-ing only one in the url Commented Sep 13, 2012 at 21:09

2 Answers 2

1

Always consider the entire URL path. Yours includes /website, so:

RewriteEngine on
RewriteBase /website
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. I made the changes, but still not achieving the result i want.
First make sure the path to comments.php is correct. If that's not the problem turn on rewrite logging and check the results. Do you have any other errors?
0

RewriteBase is used for per-directory directives. Try

RewriteEngine on 
RewriteRule ^/website/comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ /website/comments.php?topic_id=$2 

Works for me. Note that I also changed the query string parameter at the end of the line to "topic_id". Maybe this is another cause of error. If it still fails, check that the configuration is in the right virtual host config.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.