1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Looking for a decent mod_rewrite tutorial

Discussion in 'Apache' started by mxlabs, Jul 2, 2004.

  1. #1
    I used to pay people to write these tiny rewrite lines for me but I really want to learn it now. Most rewrite examples and tutorials only use 1 query string or simply dont work. I yet have to find out how to use mod_rewrite to move .php?first=x&second=y&third=z to a static version.
    SEMrush
     
    mxlabs, Jul 2, 2004 IP
    SEMrush
  2. Nitin M

    Nitin M White/Gray/Black Hat

    Messages:
    640
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #2
    http://nanoweb.si.kz/manual/mod_rewrite.html

    There are lots of ways to use rewrites. The more complex looking rules are usually built to handle many situations and are more efficient for the server vs. having lots of different specific rules which may be easier to write but put more strain on the server. Starting out it is often easier to make very specific rules until you feel more comfortable with regular expressions.

    For your example ...
    A possible solution could be:

    RewriteRule ^(.+)/first-(.*)/second-(.*)/third-(.*) $1.php?first=$2&second=$3&third=$4

    You would change your app to generate URLs that look like so to use this rule:

    www . yourdomain.com/anysubdirectories/anyphpfilename/first-x/second-y/third-z

    where "anyphpfilename" would be a php filename without the .php extension.
     
    Nitin M, Jul 2, 2004 IP
    seojig likes this.
  3. bhutz

    bhutz Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Cheers Mr Virginia Realtors....Been looking for a simple tutorial which actually explains what syntax is available but everything I have seen seems very complex and doesn't cover the basics.

    For anyone else readin this and interested in the mod_rewrite solution on a hosted server (i.e. owned by another company) I think the simplest way to test is add this line to your .htaccess

    
    RewriteEngine On
    RewriteRule ^test.php /apagethatexists.php [L]
    
    Code (markup):
    Make a back up first though ;)

    So if you had a link in your site pointing to test.php (which doesn't really exist) your browser open apagethatexists.php instead.

    Is using this to make my URL looks static likely to improve my position in google though because I understand it can handle dynamic URLs and other search engines are on the way.

    Anyone have any thoughts on this?
     
    bhutz, Jul 3, 2004 IP
  4. mxlabs

    mxlabs Peon

    Messages:
    327
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thank you Virginia Realtors, gonna have a look at it.
     
    mxlabs, Jul 3, 2004 IP
  5. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nice tutorial- found it very useful.
     
    schlottke, Jul 3, 2004 IP
  6. Owlcroft

    Owlcroft Peon

    Messages:
    645
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Owlcroft, Jul 6, 2004 IP