Forum Moderators: phranque
RewriteRule ^article/[a-z]+/([0-9]+)$ news.php?id=$1
the point, is for it to rewrite like this /article/snipped-article-title/23
the 23 being of course the articles ID.
I am scratching my head though because the rewrite rule will work for
/article/snippedarticletitle/23
As soon as I add a hyphen to the URL it breaks the rewrite. The article title is not used for a GET variable or anything, it is just junk for Google. I looked but I can't figure out how to remedy the hyphen problem. I am sure it is something pretty simple. Someone want to point me in the right direction?
Secondly, the 'allowed character list' (i.e. the list in the
[...]) does not include a hyphen. Be aware that because you do not check the value of $2 anywhere, that your site can be fake-URL-hijacked.
You link to
example.com/article/34567/this-great-product but someone else links to example.com/article/34567/overpriced-unsafe-junk and your site will serve the page as Duplicate Content with a "200 OK" status code.
RewriteRule ^article/([^/]+)/([0-9]+)$ news.php?id=$2&title-to-be-validated-against-database=$1 [L]
If the title in the requested URL does not agree with the one stored for that article id number, then instead of serving the page for that article id, your script should generate a 301-Moved Permanently redirect to the /article URL with the (correct) title that corresponds to that article id number.
Jim