Search engine friendly URLs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Berrow

    #1

    Search engine friendly URLs

    I've been trying to use .htaccess to get Apache to recognise 'article'
    as 'article.php' so I can have search engine friendly urls in the form
    article/var1/var2/var3 etc

    I have this in a .htaccess file

    <Files article>
    ForceType application/x-httpd-php
    </Files>

    This works fine on my test server but for some reason my host server
    (choice is out of my control) will not allow me to upload a .htaccess
    file.

    Is there another way of doing it?
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/
  • Geoff Berrow

    #2
    Re: Search engine friendly URLs

    Message-ID: <r4gdm2t84tsar8 ad7tpoc1idditkk n4g08@4ax.comfr om Geoff
    Berrow contained the following:
    >I've been trying to use .htaccess to get Apache to recognise 'article'
    >as 'article.php' so I can have search engine friendly urls in the form
    >article/var1/var2/var3 etc
    >
    >I have this in a .htaccess file
    >
    ><Files article>
    > ForceType application/x-httpd-php
    ></Files>
    >
    >This works fine on my test server but for some reason my host server
    >(choice is out of my control) will not allow me to upload a .htaccess
    >file.
    The file was uploaded, it was just hidden. Unfortunately it still does
    not work. mod_mime is loaded so I'm now at a loss to know what to do
    next.

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • BRADINO

      #3
      Re: Search engine friendly URLs

      Hey Geoff,

      One if the cleanest ways to setup a site is to use mod_rewrite in
      Apache. I am going to show you a simple way to do this using an
      htaccess file and a little PHP. First step is to make an htaccess file
      with the following code:

      RewriteEngine on
      RewriteCond %{SCRIPT_FILENA ME} !-f
      RewriteCond %{SCRIPT_FILENA ME} !-d
      RewriteRule ^(.*)$ index.php?loc=$ 1

      Now everything that is not a folder or a file will get passed to the
      index.php file as $_GET['loc']. You could change the index.php to any
      file you like and the ?loc= to some other variable if you like.

      Next you need to groom the url. Do not leave out this step. You are
      injecting the url into your script... I suggest something solid like
      the following:

      <?php
      $url = preg_replace('/[^[:alnum:]\-\/]/', '', $_GET['loc']);
      ?>

      So now you have the url into your script safely so you need to break it
      apart. You are basically going to pass variables here. All you have to
      do is explode on the forward slash. You can do it simply like this:

      <?php
      $parts = explode('/',$url);
      $section = $parts[0];
      $subsection = $parts[1];
      ?>


      Hope this helps!



      BRAD

      Comment

      • jopperdepopper

        #4
        Re: Search engine friendly URLs

        You may want to check out this article as well:

        Dynamic websites rock. Dynamically generated URLs suck. Till Quack shows how to use PHP to convert those machine-friendly nightmares into dreamy, human-friendly web addresses.


        good luck!

        Comment

        • Geoff Berrow

          #5
          Re: Search engine friendly URLs

          Message-ID: <1164641549.685 550.284440@h54g 2000cwb.googleg roups.comfrom
          jopperdepopper contained the following:
          >You may want to check out this article as well:
          >
          >http://www.alistapart.com/articles/succeed/
          >
          >good luck!
          Thanks for that. I've now managed to get the first method I posted to
          work (It didn't due to my stupidity in reading the instructions... ) It
          feels like an instinctively better way of doing it. Instead of passing
          everything that is not a file to a script (or in your example passing
          everything to a script) the ForceType method is specifically targeted.

          The method is this: a php file is saved /without an extension/. Let's
          say the file is called articles. The following is placed in .htaccess

          <Files article>
          ForceType application/x-httpd-php
          </Files>

          This causes Apache to treat our extensionless file as a php file. The
          URL produced just looks like a series of directories e.g.
          /article/news/local

          Obviously the directories do not exist.
          Apache has the feature of looking back up the URL till it comes to
          something it recognises - in this case our file article. article
          contains code to extract the variables from $_SERVER['REQUEST_URI']


          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          Working...