Hi, I am trying to set-up a mod rewrite on my site. Basically i have a urls which come out like: recipe-details.php?id=22&title=brie kisses This is just an example of one of the urls that i have but what i want it to do is: /recipedetails/brie-kisses.html Any ideas anyone? Cheers, Adam
RewriteEngine On RewriteRule ^recipedetails/(.*)\.html$ recipe-details.php?title=$1 Code (markup): If you want to take out the ID you will have to rewrite your PHP script so that it finds the recipe only by the title.
Thanks for your reply nico, i have added this but does not seem to work for me. I have created a .htaccess file and added the code above. I then placed this in the public_html folder but when i go to e.g. foundrecipes.com/recipe-details.php?title=beefy%20cheese%20ball It does not rewrite anything. Am i doing something wrong at all?
Ah i think we have crossed wires here. What i want it to do is auto fix any url when click for example when i search for beef and then the results show i want want the urls to automatically change when pressed to e.g. recipedetails/brie-kisses.html
You could try placing something like this in recipe-details.php. $page_title = /* adjust for your needs */; if (preg_match('/\.php$/i', basename($_SERVER['REQUEST_URI']))) { header('HTTP/1.1 301 Moved Permanently'); header('Location: recipedetails/' . preg_replace(array('/[^\w-]+/', '/-{2,}/'), '-', $page_title) . '.html'); exit(); } PHP:
I have added the above but did not seem to work This is what i put, but when i go to the page still comes up with e.g. foundrecipes.com/recipe-details.php?title=rum%20butter%20brie%20with%20fruit $page_title = "recipe-details.php?title=$_GET[title]"; if (preg_match('/\.php$/i', basename($_SERVER['REQUEST_URI']))) { header('HTTP/1.1 301 Moved Permanently'); header('Location: recipedetails/' . preg_replace(array('/[^\w-]+/', '/-{2,}/'), '-', $page_title) . '.html'); exit(); } Code (markup): Thank you for your help on this nico.