max
max

Reputation: 3716

htaccess rule doesn't work

this is my original link

http://localhost/xx/xx/public_html/news.php?id=7

i want to change it to

http://localhost/xx/xx/public_html/news-7-TitleOfNews.html

here is my htaccess

Options -Indexes 
ErrorDocument 404 www.site.com/404.html
RewriteEngine On
RewriteRule ^news-([0-9]*)(?:-([0-9a-zA-Z*]))?(?:\.html)?$ news.php?id=$1 [L]

but it doesn't work (redirect to 404 page )

Upvotes: 1

Views: 73

Answers (1)

raina77ow
raina77ow

Reputation: 106385

I suppose you're looking for this:

RewriteRule ^news-([0-9]*)(?:-[0-9a-zA-Z]*)?(?:\.html)?$ news.php?id=$1 [L]

The difference is that * quantifier should be outside of the character class expression. And wrapping the single character class into parentheses is redundant.

Upvotes: 3

Related Questions