Mr Chris Posted March 24, 2008 Share Posted March 24, 2008 Hi Guys, Say I have the headline: Man walks in Park Which is dynamically called from the database via a story_id like so: http://www.mywebbysite22.org/section.php?sec=2&story_id=3250 I'd like converted like so: http://www.mywebbysite22.org/article/2/man-walks-in-park/ So in my php code I added this line to convert the headline: $headline = $row['headline']; $clean_headline = str_replace(' ', '-', strtolower($headline)); and then tried to write this to .htaccess, but it does not work. I think i'm nearly there, but not quite: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteRule ^article/([0-9]+)/[^/]+-([0-9]+)\ $ section.php?s=$1&story_id=$2 [QSA,L] Can anyone help? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/ Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 Try: RewriteRule ^article/([0-9]+)/([a-z0-9\-]+)/$ section.php?s=$1&story_id=$2 [QSA,NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/#findComment-499573 Share on other sites More sharing options...
Mr Chris Posted March 24, 2008 Author Share Posted March 24, 2008 Thanks a lot, But it's not quite there as it's not working as it's bringing up a 404 any other suggestions? I'd like it this format: http://www.mywebbysite22.org/section.php?sec=2&story_id=3250 replaced by this: http://www.mywebbysite22.org/article/2/man-walks-in-park/ with Man Walks in Park being the headine. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/#findComment-499646 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 My rewrite rule is working fine for me. If I create a file called section.php and place it in my root and add the following code: <?php echo '<pre>' . print_r($_GET, true) . '</pre>'; ?> and go to mysite.com/article/2/man-walks-in-park/ then I get this output: Array ( [s] => 2 [story_id] => man_walks_in_part ) Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/#findComment-499714 Share on other sites More sharing options...
Mr Chris Posted March 24, 2008 Author Share Posted March 24, 2008 First of all thanks for this. I've tried the code you posted and mine shows exactly the same. Here's a live link: http://www.slougheaz.org/section.php?sec=2&story_id=3167 Which should also read as: http://www.slougheaz.org/article/2/dream-ends-in-an-instant/ However I get an SQL error as I reply upon GET in my query: $result = mysql_query("Select * from cms_stories where story_id=".$_GET['story_id']); Is this where it's failing? Is there any way I can use GET and still have the URL like so? Or do I need a story_id in there? Thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/#findComment-499735 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 as $_GET['story_id'] holds your headline man-walks-in-park you'll need to use the headline field rather than the story_id field in your query eg: $headline = mysql_real_escape_string(str_replace('-', ' ', $_GET['story_id'])); $result = mysql_query("SELECT * FROM cms_stories WHERE headline='$headline'"); Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/#findComment-499820 Share on other sites More sharing options...
Mr Chris Posted March 24, 2008 Author Share Posted March 24, 2008 Thanks, works great - thanks for all your help! ;-) Quote Link to comment https://forums.phpfreaks.com/topic/97598-mod-re-write-nearly-there-but-a-bit-oif-help-please/#findComment-499885 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.