Results 1 to 3 of 3

Thread: [RESOLVED] managing URLs

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Posts
    237

    Resolved [RESOLVED] managing URLs

    hello.. how can I make a URL like this: http://www.mywebsite.com/?select=contact" to become "http://www.mywebsite.com/contact.html" ??

    I see it all the time on the net. Thank you very much.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: managing URLs

    do you just want to redirect it, or do you want to take the input URL (?select=contact one), and transform it into the "contact.html" URL?

    I'm going to assume you want to redirect, though, (although I'm not sure why, I would assume most people would ask how to make their page index.php?select=contact, instead of just contact.html.. let me know if that's what you meant!), so.. here's what you can try, and let me know if it works out for you:
    PHP Code:
    <?php
      
    //you can change "default" to be whatever you want the "main" file
      //to be, so here i've made it index. if you don't enter a ?select,
      //or the file isn't something you've set, then it will always go
      //to the index
      
    $select = (isset($_GET['select']) && $_GET['select'] != "") ? $_GET['select'] : "index";

      switch(
    $select){
        case 
    "contact":
          
    //contact page
          
    $page "contact.html";
          break;
        
    //you can add other pages here as well, i've just added two to serve as an example
        
    case "index":
          
    //this is the -default- page,
          
    $page "index.html";
      }

      
    //now, we just redirect the user.
      
    header("Location: http://www.mywebsite.com/" $page);
    ?>
    So, if you saved that as your index.php file, if anyone went to mywebsite.com/?select=contact, they would be redirected to mywebsite.com/contact.html instead.

    edit: Also, if you wanted the index to still display normally, it's easy to change so that only certain pages get redirected and others display through the index. but, let me know if that was what you wanted.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: managing URLs

    Quote Originally Posted by jimot
    hello.. how can I make a URL like this: http://www.mywebsite.com/?select=contact" to become "http://www.mywebsite.com/contact.html" ??

    I see it all the time on the net. Thank you very much.
    The trick you are after uses MOD_REWRITE which is part of the Apache server.

    For example I type lordmatt.co.uk/item/xxx but the script is called as lordmatt.co.uk/index.php?itemid=xxx

    This is achieved using settings in .htaccess (a file) please note that ti starts with a dot and is therefore by windows standards all extension and no file name...

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    This tells apache that it needs to be using rewrite. I'm unclear as to "Options +FollowSymlinks" but I understand it is best to use it.

    There are a few things you can do

    1. Set conditions
    2. Rewrite
    3. USe RegEx

    This example corrects old urls for my wiki.

    Code:
    RewriteCond %{HTTP_HOST} !^wiki\.lordmatt\.co\.uk(.*)$ [NC]
    RewriteCond %{REQUEST_URI} ^/wiki/ [NC]
    RewriteRule ^wiki(.*)$  http://wiki.lordmatt.co.uk$1 [R=301,NC,L]
    The first two lines look at the conditions the !means that URLS that are NOT wiki.lordmatt.co.uk and [NC] means No Case (case INsensitive).

    The second condition means that the base url + /wiki/ is required in the URL

    Then we take wiki and everything after it and put the everything to the end of the new url wiki.lordmatt.co.uk{{anything else}}.

    [R=301] is HTTP code for permanant redirect which should be used only if you want the user to be aware of the change and tells the search engines to update thier records. [L] means last. If we are processing this line we process no more.

    No most of the complex stuff is RegEx so if you are looking at it blankly (like I first did a year ago google a lot and eventually you will get the idea or be confused totaly )

    Here is what you might want to do using my domain as an example.

    The example uses NucleusCMS which I run on lordmatt.co.uk

    Code:
    RewriteRule ^archive-([0-9]+)-([0-9]+)-([0-9]+).html+ index.php?archive=$2-$3&blogid=$1
    RewriteRule ^item-([0-9]+).html+ index.php?itemid=$1
    RewriteRule ^archivelist-([a-z]+).html+ index.php?archivelist=$1
    I figure that should get you started.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width