Jump to content

mod re-write - nearly there, but a bit oif help please ;-)


Mr Chris

Recommended Posts

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

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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'");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.