ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.

July 11, 2008 6:03am

Subscribe [0]
  • #1 / Jul 11, 2008 6:03am

    pickledegg2

    157 posts

    I’m probably breaking all the rules of eticate again, but this isn’t really CI related, so I popped it in the lounge. I need someone to ‘teach me how to fish’ 😊

    I’m ( for the first time ) trying to get to grips with mod_rewrite. I’m hoping someone can offer some examples to get me going, and I can tweak them, but right now I’m at a brick wall. I think I’m ok with things like adding the www on the front and stuff, its just the more detailed rules I’m struggling with.

    Heres what I want to do:
    From the root, any number of letters or numbers followed by a slash and nothing else:

    <a href="http://www.mysite.com/about/">http://www.mysite.com/about/</a>

    Remove the slash and replace with a .php:

    <a href="http://www.mysite.com/about.php">http://www.mysite.com/about.php</a>

    *Except don’t rewrite a specified one, leave as is:

    <a href="http://www.mysite.com/contact/">http://www.mysite.com/contact/</a>

    A similar thing for the products folder:

    <a href="http://www.mysite.com/products/satellite/">http://www.mysite.com/products/satellite/</a>

    to

    <a href="http://www.mysite.com/products/satellite.php">http://www.mysite.com/products/satellite.php</a>

    and finally:

    <a href="http://www.mysite.com/products/satellite/rent/">http://www.mysite.com/products/satellite/rent/</a>

    to remove the end slash and swap with a .php, and replace /rent with -rent

    <a href="http://www.mysite.com/products/satellite-rent.php">http://www.mysite.com/products/satellite-rent.php</a>

    I’m not asking for someone to just do this for me (ok so maybe I am), but I think if I’ve got a couple of examples, I’ll be able to see how its done. I’ve got a load more rules to add for things like url parameters, but I want to have a bash at those, hopefully with the knowledge I’m gained from these ones…

  • #2 / Jul 11, 2008 8:06am

    pickledegg2

    157 posts

    Ok I’m nearly there, the only one I’m stuck on now is this:

    <a href="http://www.mysite.com/products/satellite/rent/">http://www.mysite.com/products/satellite/rent/</a>

    to remove the end slash and swap with a .php, and replace /rent with -rent

    <a href="http://www.mysite.com/products/satellite-rent.php">http://www.mysite.com/products/satellite-rent.php</a>

    Can anyone offer any tips?

  • #3 / Jul 11, 2008 10:53am

    pickledegg2

    157 posts

    Ok I’ve sussed that one out now.

  • #4 / Jul 12, 2008 6:34am

    garymardell

    315 posts

    Care to share how you did it, incase anyone else is interested in learning how to do it.

  • #5 / Jul 16, 2008 8:35am

    pickledegg2

    157 posts

    Sorry bud I’ve done that thing haven’t I?

    Yes of course I can share it:

    This one turns this (if the last part of the url is ‘rent’ or ‘buy’):
    http://www.mysite.com/products/satellite/rent/
    into this:
    http://www.mysite.com/products/satellite-rent.php

    RewriteRule ^products/(.+)/(rent|buy)/$ /products/$1-$2.php [L]
    RewriteRule ^products/(.+)/$ /products/$1.php [L]

    and this one turns this:
    http://www.mysite.com/products/satellite/
    into this (if the folder is NOT ‘products’ or ‘contact’):
    http://www.mysite.com/products/satellite.php

    RewriteCond %{REQUEST_URI} !^/contact/$
    RewriteCond %{REQUEST_URI} !^/products/.*$
    RewriteRule ^(.*)/$ /$1\.php

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases