mod rewrite help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinpkl
    New Member
    • Oct 2008
    • 41

    mod rewrite help needed

    hi all

    i have a url like
    description.php ?id=$1
    i used rewrite to make it seo friendly
    RewriteRule ^product([^/\.]+)?.html$ description.php ?id=$1
    it gives me
    product7.html
    now i want to replace "product" word with dynamic word coming from database like Nokia N95 or LG Viewty

    how can i do it.

    what should i write in rewrite rule so that it accept dynamic word inplace of "product".

    so that my url become
    LG-viewty7.html

    vineet
  • dumm
    New Member
    • Dec 2008
    • 10

    #2
    Code:
    RewriteRule ^.*([a-zA-Z\-]+)([0-9]+).html$ description.php?section=$1&id=$2
    Where "section" become your dynamic word.

    Comment

    • vinpkl
      New Member
      • Oct 2008
      • 41

      #3
      mod rewrite

      Originally posted by dumm
      Code:
      RewriteRule ^.*([a-zA-Z\-]+)([0-9]+).html$ description.php?section=$1&id=$2
      Where "section" become your dynamic word.
      hi dumm

      thanks. thats what i needed.

      vineet

      Comment

      • xNephilimx
        Recognized Expert New Member
        • Jun 2007
        • 213

        #4
        dumm solution is right, but is really everything after your domain going to be a product? I reccomend you to do the following:

        RewriteRule ^products/([a-zA-Z\-]+)([0-9]+).html$ description.php ?section=$1&id= $2

        So the rewritten url will look like products/LG-viewty7.html and you will have no problems if you want, say, add a contact page /contact.html.

        Remember, that since a fake subfolder is added, all the relative urls (links, images, etc) should be passed to absolute urls, or else the browsers will try to look any relative url inside the products folder, that doesn't really exists.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          I like to do this because it's much more flexible:

          [code=htaccess]
          # Virtualize anything that doesn't already exist.
          RewriteCond %{REQUEST_FILEN AME} !-f
          RewriteCond %{REQUEST_FILEN AME} !-d
          RewriteRule ^.*([a-zA-Z\-]+)([0-9]+).html$ description.php ?section=$1&id= $2
          [/code]

          Comment

          Working...