Dot Oyes
Dot Oyes

Reputation: 163

URL Rewriting with .HTACCESS not working in php

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.

Upvotes: 0

Views: 158

Answers (2)

ofrommel
ofrommel

Reputation: 2177

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.

Upvotes: 0

Matt S
Matt S

Reputation: 15364

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

Upvotes: 1

Related Questions