SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    have a ' symbol in the title

    Hi Chaps.... i hope you can help me (rather quickly!!)

    Ive had a site on my server prior to it actually going live, now, on the other server project titles with a ' in the name are failing whereas on the test server it was fine

    in the htaccess im using
    Code:
    rewriterule ^event_detail/([^&]+)/([^&]+)/([A-Z0-9-&'@:!?\(\)\ ]+)$ /event_detail.php?eventid=$1&cat1=$2&eventtitle=$3 [NC,L]
    and the actual url is

    HTML Code:
    /event_detail/328/Family/Handa's-Hen
    I hope someone can help, as ive made the site live and its rather embarrassing having dead links!

    Many thanks in advance

    b

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Barney,

    Your mod_rewrite looks okay with only a couple of comments:

    NC shouldn't be use here as that's designed for case INsensitive {HTTP_HOST}. You really should replace A-Z with a-zA-Z.

    As for your regex, you're using digits for $1 and letters for $2 so use that for your range definitions ( ([0-9]+) and ([a-zA-Z]+ ).

    I'm using similar code at wilderness-wally.com and ONLY use the equivalent of your $3:
    Code:
    RewriteRule ^([-a-zA-Z0-9_&'!]+)$ script.php?title=$1 [L]
    and fetch the content based on the title field (after replacing the _'s with spaces to reverse the process used to create the links). That way, I can even allow the use of the ampersand (&) in the titles!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK.. i tried your ([-a-zA-Z0-9_&'!]+), however this failed..and also for evenst with the old & thrown in, so i went back to what i did initially.

    For the sent variables, im pulling the record down from the ID, the Cat is a filler for the Categories and the title is used just to form the url.

    As i mentioned, on the other server everything is fine, on the new server, this fails

    event_detail/328/Family/Handa's-Hen

    however if i change the address to

    event_detail/328/Family/Handas-Hen

    it works fine....

    So there must be something wrong with the last segment that is ignoring the '

    Or could there be a problem with the apache version or something?

    cheers

    b

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Barney,

    Actually, if you're not using the title for anything, WHY are you bothering to capture it and put it in the {REQUEST_URI} string?
    Code:
    RewriteRule ^event_detail/([0-9]+)/([a-zA-Z]+)/.+ /event_detail.php?eventid=$1&cat1=$2 [L]
    Wouldn't that do the trick?

    As I said above, the Wilderness Wally website uses the code shown above and ONLY uses the title field to fetch the correct record. It HAS to be right to work - and the server is constantly updated so there's nothing new in Apache that prevents it from working.

    If you make Apache do more than you NEED it to do, it's only slowing the serving of your pages. On a shared server, that needless effort gets magnified by the hundreds of users making the same error.

    Regards,

    DK
    Last edited by dklynn; Nov 24, 2009 at 15:43. Reason: Wilderness-Wally
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How rude of me not to reply!

    Thanks it works fine....its the first time that ive used seo friendly urls, and i 'presumed' the data (title), whether i used or not, needed to be in the string for it to show in the browser.....

    Thinking laterally though, if i did want to pull down the record based on the title, how could i do this the title contained a ' ?

    many thanks

    b

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    barney,

    In MySQL, the ' character must be escaped (mysqli_real_escape_string() does a good job on that) but I use the following "scrub" on the title when received:
    Code:
    	$title = (isset($_GET['title']) && !empty($_GET['title'])) ? str_replace(array("_"),array(" "),$_GET['title']) : ""; 
    } else {
    	$title = (isset($_GET['title']) && !empty($_GET['title'])) ? str_replace(array("_","'"),array(" ","\'"),$_GET['title']) : ""; 
    
    // THEN
    
    $sql = "SELECT * FROM blog WHERE title = '".mysqli_real_escape_string($dbconnector,$title). "' " ;
    That first checks that the query string contains title (created by the mod_rewrite; if not, the Welcome page is requested with the SQL query which I've removed here for simplicity) then uses str_replace (for the speed) to check on _s and 's in the string and convert to " " (space) and \' (escaped ') before taking it to the db for a match of the title field contents with a final "cleanup" provided by mysqli_real_escape_string(). Easy as pie!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •