SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Mod Rewite newbe

    I am learning mod rewrites and finding it difficult where to start.

    If someone can show me sample code for the following, I think that will help:

    (1) Simple redirect when they enter www.site.com/view.html to view the page on the server: www.site.com/pages/view.php

    (2) Simple redirect like 1 but to append a variable. So they enter www.site.com/jim-brown and I want it to use www.site.com/profile.php?nm=jim-brown

    I know most people will say I need to learn it myself but this will help me start.

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

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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

  3. #3
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it's not helpful. There's too much. Thanks anyway though.

    I just want to learn the basics and expand on that over the next few years.

    I've seen on another, very simple, tutorial that this redirects one file to another:

    RewriteRule ^fileone.html$ filetwo.html

    - but I need to know how to do this:

    RewriteRule ^{filename}/{variable}$ {filename}.html?var={variable}

    I like to learn the basics first one step at a time.

    Thanks for taking the time to respond though.

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

    I have a history of NOT posting code until someone at least makes an attempt. However, let's say that your pseudo code is "close enough for government work."

    Quote Originally Posted by johnsmith153 View Post
    Code:
    RewriteRule ^fileone.html$ filetwo.html
    could simply be edited to:[code]RewriteEngine on
    RewriteRule ^fileone\.html$ filetwo.html [R=301,L]
    Where the first line is merely getting mod_rewrite ready to go, the \ merely forces the dot charater to be a dot character (not a metacharacter representing ANY character) and the Last flag added so this RewriteRule is not ANDed with any succeeding rules.

    - but I need to know how to do this:
    Code:
    RewriteRule ^{filename}/{variable}$ {filename}.html?var={variable}
    Edited to:
    Code:
    # pseudo code
    # RewriteRule ^{filename}/{variable}$ {filename}.html?var={variable}
    # replace pseudo code
    RewriteRule ^([a-z.]+)/([a-z.]+)$ $1.html?var=$2 [L]
    Where the {filename} and {variable} consist ONLY of one or more lowercase letters and, perhaps, a dot character (for a file extension).

    I like to learn the basics first one step at a time.

    Thanks for taking the time to respond though.
    I'm a bit confused that you say you'd like to learn the basics one step at a time but found the long tutorial too much. I tried to "take it one step at a time" and used a LOT of sample code to help the reader along. Okay, this is the first time someone's not come back with "that's exactly what I needed" so any comments (other than length, too much information, not precisely the coding samples I need) would be appreciated.

    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
  •