Simpler urls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Furman

    Simpler urls

    I want to have urls that work like the php.net pages where there's just
    a word after a slash, maybe a few folders deep. Right now I've got urls
    & code like this:


    But I'd prefer:


    <?php
    function chk_screen(){
    $default_screen = 'home.php'; # the default screen
    if(isset($_REQU EST['SC'])) {
    if(is_file(SCRE EN_DIR . "/" . basename($_REQU EST['SC']))) {
    $SCREEN = basename($_REQU EST['SC']);
    } else {
    $SCREEN = $default_screen ;
    }

    if($SCREEN == 'main.php') {
    $SCREEN = 'home.php';
    $_REQUEST['SC'] = $SCREEN;
    }
    } else {
    $SCREEN = $default_screen ;
    }
    return $SCREEN;
    }?>

    The images are stored in a folder heirarchy, there is no database but
    I'm guessing I'll have to add one with an index & serial numbers for
    each image. The folder structure is part of the properties of each image
    though:
    &DIR=Califor nia/Bay-Area/San-Francisco/neighborhoods/2007-06-19-stanyan
    then the url gets this too:
    &PG=1&PIC=1

    I'd like to see at most:

    Ideally it could trim off most of that in hidden POST data?
    (I forget how)

    I could just try snipping off the "1/?SC=go.php&DIR= " and "&PG=1&PIC= 1"


    or add a database & use something like this:


    Part of the effort is to create a fresh set of folders & the old archive
    folders remain as the 'database' and sorted by location & date. One such
    new folder could be a blog with my (usually weekly) photo updates, then
    categories for nature, plants, landscapes, people.

    I've built the collection with text files for captions & the folders
    with date & location so I guess all that needs to go in a database & get
    indexed.

    --
    Paul Furman Photography

    Bay Natives Nursery

  • NC

    #2
    Re: Simpler urls

    On Jul 10, 3:56 pm, Paul Furman <p...@-edgehill.netwro te:
    >
    I want to have urls that work like the php.net
    pages where there's just a word after a slash,
    maybe a few folders deep.
    This has almost nothing to do with PHP. This is a HTTP server-level
    problem. Apache has a module called mod_rewrite, which can be
    configured to accomplish what you want:



    [skipped]
    I'd like to see at most:
    http://www.edgehill.net/California/B...San-Francisco/[skipped]
    If your hosting company allows .htaccess files, add these lines to
    your .htaccess file in the site's root directory:

    RewriteEngine on
    RewriteRule ^California(.*) $ /1/?SC=go.php&DIR= California$1 [NC,L]

    This should do the trick.

    Cheers,
    NC

    Comment

    • Rik

      #3
      Re: Simpler urls

      >>Hence, the links:
      > Ack... regular expressions!!!! !!!!!
      > Anyone interested in a little consulting to get me up to speed on a
      >basic framework for this system, please email. I've got a couple web
      >sites that could use this upgrade but it's beyond me for now to even
      >get a basic effect to take hold with .htaccess on the first one I tried.
      >
      I'd suggest you try asking in alt.apache.conf iguration. That's where
      those gurus hang out.
      >
      There are a few here with knowledge about how to do it, but many more
      over there.
      Well, if htaccess isn't your thing, there's one other pretty easy brute
      force thing to do:

      Simple htaccess:

      RewriteEngine On

      RewriteCond %{REQUEST_FILEN AME} !-f
      RewriteCond %{REQUEST_FILEN AME} !-d
      RewriteRule .* index.php [L,QSA]

      This will throw requests for non-existant files or folders to your
      index.php. Search the $_SERVER['REQUEST_URI'] for the original request,
      and have fun in PHP instead of .htaccess. Exploding, loops, databases, all
      at your disposal.

      If the request doesn't make sense, please throw out a not-found header in
      PHP, search engines generally appreciate that. And realise your server
      will have a lot more heavier load in this setup, as the webserver itself
      isn't responsible anymore for it's own fast returns, but everything goes
      through PHP.

      HTH
      --
      Rik Wasmus

      Comment

      • Paul Furman

        #4
        Re: RewriteEngine consulting

        Sorry, that was supposed to go to alt.apache.conf iguration

        Paul Furman wrote:
        Hi, can someone help me with consulting to migrate to a RewriteEngine
        configuration? This looks like more than I can bite off, I could use
        some help.
        >
        Thanks,
        Paul
        >
        Jerry Stuckle wrote:
        >
        I'd suggest you try asking in alt.apache.conf iguration.

        Comment

        • Jerry Stuckle

          #5
          Re: RewriteEngine consulting

          Paul Furman wrote:
          Sorry, that was supposed to go to alt.apache.conf iguration
          >
          Paul Furman wrote:
          >Hi, can someone help me with consulting to migrate to a RewriteEngine
          >configuratio n? This looks like more than I can bite off, I could use
          >some help.
          >>
          >Thanks,
          >Paul
          >>
          >Jerry Stuckle wrote:
          > >
          > I'd suggest you try asking in alt.apache.conf iguration.
          :-)

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Paul Furman

            #6
            Re: Simpler urls

            NC wrote:
            Paul Furman wrote:
            >
            >>I want to have urls that work like the php.net
            >>pages where there's just a word after a slash,
            >>maybe a few folders deep.
            >
            This has almost nothing to do with PHP. This is a HTTP server-level
            problem. Apache has a module called mod_rewrite, which can be
            configured to accomplish what you want:
            >


            >
            >>Right now I've got urls & code like this:
            >>http://www.edgehill.net/1/?SC=go.php&DIR=California
            >>
            >>But I'd prefer:
            >>http://www.edgehill.net/California
            >>
            If your hosting company allows .htaccess files, add these lines to
            your .htaccess file in the site's root directory:
            >
            RewriteEngine on
            RewriteRule ^California(.*) $ /1/?SC=go.php&DIR= California$1 [NC,L]
            >
            This should do the trick.
            Hmm, OK I looked into this some more and it doesn't appear to be
            practical because I have a huge number of destination urls & as I
            understand, I'd need to actually list all those in the .htaccess file.
            It seems I might be better off doing my own parsing in php which also
            would not be easy but then I could direct things more flexibly &
            accommodate any number of destination urls. Does this sound right?

            --
            Paul Furman Photography

            Bay Natives Nursery

            Comment

            • Michael Fesser

              #7
              Re: Simpler urls

              ..oO(Paul Furman)
              >Hmm, OK I looked into this some more and it doesn't appear to be
              >practical because I have a huge number of destination urls & as I
              >understand, I'd need to actually list all those in the .htaccess file.
              This depends on the URLs. Of course listing all possible URLs is
              absolutely pointless. That's not what regular expressions are for.
              But if there would be a common structure inside them, like



              you could easily match all of them with a single regular expression.

              Micha

              Comment

              • Paul Furman

                #8
                Re: Simpler urls

                Michael Fesser wrote:
                .oO(Paul Furman)
                >
                >
                >>Hmm, OK I looked into this some more and it doesn't appear to be
                >>practical because I have a huge number of destination urls & as I
                >>understand, I'd need to actually list all those in the .htaccess file.
                >
                >
                This depends on the URLs. Of course listing all possible URLs is
                absolutely pointless. That's not what regular expressions are for.
                But if there would be a common structure inside them, like
                >

                >
                you could easily match all of them with a single regular expression.
                Just a followup, I found a consultant to tutor me through this and I got
                away with just rewriting the top level folders in .htaccess then
                allowing any number of subfolders to be appended. Here's what it looks like:

                RewriteRule ^gallery/?$
                index.php?SC=go .php&DIR=0_gall ery [NC]

                RewriteRule ^gallery/Photo-Update(/.+)?$
                index.php?SC=go .php&DIR=0_gall ery/0-Photo-Update$1 [NC]

                RewriteRule ^gallery/(.+)$
                index.php?SC=go .php&DIR=0_gall ery/$1 [NC]

                Then I also have to go back & rewite my links to the new format. I'm
                still working out plenty of bugs but I got the basic thing rolling.

                --
                Paul Furman Photography

                Bay Natives Nursery

                Comment

                Working...