Giddy Rob Posted September 2, 2010 Share Posted September 2, 2010 Hey, I need to change the url so that "www.website.com/item.php?id=1504" will read something more user friendly and better seo. I've heard you do it with a mod_rewrite, but have never done this before so was wondering if someone could show me how? it would be nice if I could output "www.website.com/newstitle_1504.html" where newstitle is the title of the news item being displayed ie this will be different for each article Example would be great Cheers Quote Link to comment https://forums.phpfreaks.com/topic/212341-php-mod_rewrite/ Share on other sites More sharing options...
cags Posted September 2, 2010 Share Posted September 2, 2010 You change all the links on your site so that they link to the 'pretty' version. Then use something like the following... <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^[a-zA-Z0-9-]+_([0-9]+)\.html /item.php?id=$1 </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/212341-php-mod_rewrite/#findComment-1106486 Share on other sites More sharing options...
PradeepKr Posted September 4, 2010 Share Posted September 4, 2010 I usually take care of .html and .htm extensions in putting a question mark just after .html (html?). This works for both the extensions .htm as well as .html. RewriteRule ^[a-zA-Z0-9-]+_([0-9]+)\.html? /item.php?id=$1 Quote Link to comment https://forums.phpfreaks.com/topic/212341-php-mod_rewrite/#findComment-1107146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.