SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Htaccess help

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Htaccess help

    I have a URL that I would like to make it to look nicer
    like http://www.your-site.cm/action/name-of-movie

    http://www.your-site.cm/movie.php?cat=$1&movie=$2

    anyone

    thanks

  2. #2
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    RewriteEngine On
    RewriteRule ^(.*)/(.*)$ /movie.php?cat=$1&movie=$2
    That should do it.

    But be careful because if someone goes to http://www.site.com/contact/blah it will class contact as a category and blah as a movie...

    You'd be better off having for example: http://www.site.com/categories/action
    http://www.site.com/movies/name-of-movie
    :-)

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

    Thanks for the effort but that's BAD advice (IMHO).

    sinz,

    [rant #1]
    The use of "lazy regex," specifically the EVERYTHING atom, (.*), and its close relatives, is the NUMBER ONE coding error of newbies BECAUSE it is "greedy." Unless you provide an "exit" from your redirection, you will ALWAYS end up in a loop!
    [/rant #1]

    My advice is to learn a little regex rather than use "lazy regex" which gets noobies in more trouble than they can handle (looping is the primary example but (.*)/(.*) will sent even 'directory/' to movie.php and that's NOT what you need (especially if you have css, js, image files in subdirectories.

    If you need a place to start learning about the simplified regex used by mod_rewrite, please start with the tutorial linked in my signature.

    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
  •