SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SEO Urls - MOD REWRITE

    Does anyone can help in converting this URL:

    http://b2b.rishta4u.com/cat_sell.php?cid=89

    into :

    http://b2b.rishta4u.com/cat_sell/89.html or anything else that is SEO friendly using mod rewrite.

    Do I need after sucessful mod rewrite to implement some changes on PHP pages (for an example cat_sell.php - do I need here something to change).

    Thank you for your help.

    dikimiki

  2. #2
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mod_rewrite doesn't require any changes in the php files.
    as for the conversion,
    1. this is the wrong forum for it
    2. it, there's tonnes on mod_rewrite out there already

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to use something like this:

    Code:
    RewriteEngine On
    RewriteRule ^cat_sell/([0-9]+)\.html$  cat_sell.php?cid=$1
    And no, you don't have to change anything in your script.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  4. #4
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lilleman,

    Thank you very much but I couldn't see any change in site's links. Links are the same as before. Should I change into PHP script link to be as rewriten links. This PHP script uses queries from MySQL database when assigning CIDs from database, like <?=cid?>.

    It doesn't work.

    Thank you.

  5. #5
    SitePoint Member summean's Avatar
    Join Date
    Jun 2005
    Location
    Birmingham, AL
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I'm pretty sure you'll have to change your actual links to reflect the new URLs in your script.

  6. #6
    Non-Member
    Join Date
    May 2005
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeh go to 89.html and it shud go to the correct page with the correct db info

  7. #7
    SitePoint Evangelist -Oz-'s Avatar
    Join Date
    Nov 2001
    Location
    Phoenix, AZ, USA
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by summean
    Yeah, I'm pretty sure you'll have to change your actual links to reflect the new URLs in your script.
    exactly, so you do have to modify your scripts to reflect the new url structure, but other than that no real deep modification is needed.
    Oz
    GamersMark - On Target Gaming
    OzTheory - Programming and Web Solutions
    AmIBlocked - Check if you've been blocked on IM

  8. #8
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a quick ammendment. Use this, it ensures that nothing is carried on after the rule is done:

    Code:
    RewriteEngine On
    RewriteRule ^cat_sell/([0-9]+)\.html$ cat_sell.php?cid=$1 [L]

  9. #9
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have written this mod rewrite

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^([^\/]+)\/([^\/]+)\/([0-9]+)\.html$ /$1.php?$2=$3

    and I changed a link to be as :

    <a href="cat_sell/cid/<? echo $cats["sb_id"];?>.html"><? echo $cats["sb_cat_name"]; ?></a>&nbsp;(<? echo $sbtotal; ?>)

    and it works partially. A page /cat_sell/cid/89.html is shown but no pictures are shown on this page and other links are not followed (didn't rewrite all links that are from the same cat_sell.php script)

  10. #10
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am totally knew to mod rewrite, but does mod-rewrite not force you to use absolute links to images?

    At least, that's how I interpreted the manual..

  11. #11
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^\/]+)\/([^\/]+)\/([0-9]+)\.html$ $1.php?$2=$3 [L]
    Give that a try. Im finding it hard to understand the problems you are facing. Please try explaining yourself better

  12. #12
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The difficulties are that .htaccess works fine after I change <a href=....
    but only one level. When rewriten query page loads like cat_sell/cid/89.html on this page I have more links that use the same script cat_sell.php?cid=number but here I got 404 blank page. I changed correctly <a href=... as on index.php file but when I change on cat_sell.php file I got this 404 blank page.

    these are links:

    http://b2b.rishta4u.com/cat_sell/cid/89.html (from index page mod rewrite works fine) but on this page do not work.

    I can't resolve what's the problem.

    this is a link code:

    <a href="cat_sell/cid/<? echo $cats["sb_id"];?>.html"><? echo $cats["sb_cat_name"]; ?></a>&nbsp;(<? echo $sbtotal; ?>)

    Thank you.

  13. #13
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    You got the correct answer from Lilleman and Dean_C so why did you go off and try to reinvent the wheel? Just include Dean's version in the .htaccess in your root directory and be done with it.

    YES, you DO have to change your PHP script - to use the new style links (nobody's going to guess what your regex is looking for).

    YES, your (relative linked) images will "go away" after this redirection.

    ALL of the above has been covered in the article at datakoncepts.com/seo so all you need to do is read and absorb.

    WARNING: Your ([^\/]+) atoms can be almost as dangerous as the dreaded EVERYTHING atom (.*) as it passes everything except the \ and /. Learn to be specific about what you will allow to pass as a (weak) first line of defense against hackers.

    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

  15. #15
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn
    YES, you DO have to change your PHP script - to use the new style links [...]
    Ah yes, that's true. I didn't think of that.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Erik,

    Don't worry about that! I make the assumption that they've got mod_rewrite enabled and you'd be surprised how many times that's not been a good assumption! That was why I'd written that article I go on about all the time (to save repeating myself repetitively ) 'cause I tried to cover all the basics in there.

    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
  •