Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Changing URL

  1. #1
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    922
    Thanks
    76
    Thanked 29 Times in 29 Posts

    Changing URL

    Good evening,

    I have a website using php to set the pages up. My URL is showing as: http://localhost/GardenableImproved/?page=contact for example.

    How can I change it so that it displays as: http://localhost/GardenableImproved/Contact?

    Here is a bit of code:
    PHP Code:
    $pages scandir("{$dir}/pages");

    unset(
    $pages[0],$pages[1]);

    foreach (
    $pages as &$page){
       
    $page substr($page0strpos($page'.'));
    }

    if(
    in_array($_GET['page'], $pages)){

        
    $title ucwords($_GET['page']);
        
    $include_page "{$dir}/pages/{$title}.template.htm";
    }
    else
    {
       
    header("Location: ?page=home");
       die();

    I'm trying to use the $title variable to set it up but I don't know how to or where to. This file is included in my main index.php file.

    Thank you for your time.

    Kind regards,

    LC.

  • #2
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    922
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Just wrote this quickly.
    PHP Code:
    $uri $_SERVER['REQUEST_URI'];
        
        
    $uri substr_replace($uri$titlestrrpos($uri"/") + 1);
        echo 
    $uri
    I am getting: /GardenableImproved/Contact as output at the top of the screen, but the URL is the same. How can I now force the URL to be equal to that string?

    Kind regards,

    LC.

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,915
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Just put that index page in a directory named Contact which is inside the dir named GardenableImproved.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #4
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    922
    Thanks
    76
    Thanked 29 Times in 29 Posts
    My structure is setup like this:

    [] = directory
    --> = sub-directory
    * = file

    [GardenableImproved]
    * index.php
    -->[core]
    *setup.php
    -->[pages]
    *contact.template.htm

    setup.php contains the code above so as you can see, I can't change the site structure too much as there are many other files which use paths etc.

    Are there any other ways to acvhieve it?

    Could I force a header() redirect?

    Thanks for the reply.

    Kind regards,

    LC.


  •  

    Posting Permissions

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