How to efficiently rename website URL's?

by goonie
8 replies
Lets say I'm creating a website about with 4 pages about bananas, apples, tomatoes and carrots, so I currently have 4 `.html` files: `bananas.php`, `apples.php` etc.

I suppose I would like to have `bananas.php` show as:

`domain.com/fruits/bananas-are-good/` (as I see many websites do it that way),

and `carrots.php` to show as `domain.com/vegetables/carrots-info/` and so on.

meaning I want to:

1. have a categorizing subfolder
2. not have any `.php` in the url
3. have a custom, longer name for each page.

What are my options and what is most recommended to achieve this?

I know I can manually create a folder in my domain's root folder named "fruits",
and then create a folder named "bananas-are-good",
and then upload bananas.php as index.php.

But I don't think this is what pro webmasters really do.

I suppose you might tell me there's an option to create an .htaccess rule that changes each ".php" in the url to a "/", but then I would still have to rename my `bananas.php` file to `bananas-are-good.php` on my computer/root folder, and I would still have to create the "Fruits" folder, which is not comfortable **in case I want to update all the .php files on my website at once via ftp** (as I would have to manually go to each subfolder, and upload the relevant files, instead of uploading everything at once) - what if I would have 20 folders? it would be exhausting and inefficient.

**I would also need to link the pages to each other, and I'm not sure how should they be linked?** would I have to use absolute url's? (like change the link in my `apples.php` from the current `<a href = "bananas.php">` to `<a href = "http://domain.com/fruits/bananas-are-good/">` .

I would also want to reserve the option to have visitors arriving to links like `mydomain.com/vegetables/carrots-info/?referrer=name` (In case that matters anything).

So what is the best all round solution? I'm hoping there's an easy, free, and quick solution that does not require complicated tech skills (nor install anything), and that would allow my to keep using FTP for updating the website, and not some sort of a web interface.

Thanks!
#efficiently #rename #url #website
  • Profile picture of the author RobinInTexas
    The easiest way to do it would be to install WordPress.

    WordPress will structure things that way based on a very common permalink setting used by tens of thousands of sites.
    Signature

    Robin



    ...Even if you're on the right track, you'll get run over if you just set there.
    {{ DiscussionBoard.errors[9042918].message }}
  • Profile picture of the author goonie
    Well, call me old school but I don't use WP for building my websites. Only Dreamweaver and that's it...
    {{ DiscussionBoard.errors[9042923].message }}
  • Profile picture of the author SJL
    You need to look into "htaccess clean urls". I can post easy, ready to use example later if you want. But i don't have time at this second.

    But one thing's for sure. None of the pro admins code every page totally from scratch these days. That ruins the whole point of php.
    {{ DiscussionBoard.errors[9043223].message }}
  • Profile picture of the author valvednd
    if your using a decent php mvc framework like cake or codeigniter you can use named routes like such:

    http://bakery.cakephp.org/articles/F...ting-explained

    or

    http://ellislab.com/codeigniter/user...l/routing.html
    {{ DiscussionBoard.errors[9044033].message }}
  • Profile picture of the author joe ferdinando
    You can also use this method:

    Code:
    How to create SEO friendly URL in PHP.
    my old url included in ? = %  but i want to create /services.php or /keywords.php
    please suggest me code[/quote]
    
    To create SEO friendly URLs all you need is a little file called .htaccess.
    
    
    Step 1
    Open up your text editor and type the following:
    RewriteEngine On
    RewriteRule ^([^/.]+)/?$ /index.php?page=$1
    
    Save this as .htaccess and upload to your webserver.
    If you type www.yoursite.com/example, the Apache web server will now interpret it as www.yoursite.com/index.php?page=example
    
    
    Step 2
    The SEO friendly URLs should work now, but you also need a PHP script that will include the subpages.
    The following script is set to include all pages from a directory called "inc", but change it to whatever you like.
    
    Note: This should be in your index.php file where the main content appear.
    <?php
    $page = $_GET['page'];
     
    $def = "home";
    $dir = "inc";
    $ext = "php";
     
    if (isset($page)) {
        $page = substr(strtolower(preg_replace('([^a-zA-Z0-9-/])', '', $page)), 0, 20);
        if (file_exists("$dir/$page.$ext") and is_readable("$dir/$page.$ext")) {
            include("$dir/$page.$ext");
        }
        else {
            include("$dir/error404.$ext");
        }
    }
    else {
        include("$dir/$def.$ext");
    }
    ?>
    
    
    Step 3
    Change all internal links and replace them with your new SEO links.
    For example, if you have a link to index.php?page=about, change this to about.
    
    You're finished! Open your website and try to enter the short SEO friendly URL.
    Signature
    {{ DiscussionBoard.errors[9044417].message }}
  • {{ DiscussionBoard.errors[9047335].message }}
  • Profile picture of the author goonie
    I'm a little confused,
    While my pages are .php, is it really necessary to use PHP in order to achieve the rewriting? isn't plain .htacess editing is enough?

    Joe Ferdinado's example is relevant only for a case where all pages would carry a similar url pattern, whereas I'm looking to have url that look like:

    .com/category/name
    .com/category2/name
    .com/category/name2
    .com/name3

    I don't want to use WP as all my site is already built with regular html/php, and I've heard WP also takes a lot of resources, so I wouldn't want to install it just for the sake of having nice URLs.

    Yet I do acknowledge that it would be inefficient to code everything from scratch, so what's the best solution for me?
    {{ DiscussionBoard.errors[9066982].message }}
    • Profile picture of the author joe ferdinando
      Originally Posted by goonie View Post

      I'm a little confused,
      While my pages are .php, is it really necessary to use PHP in order to achieve the rewriting? isn't plain .htacess editing is enough?

      Joe Ferdinado's example is relevant only for a case where all pages would carry a similar url pattern, whereas I'm looking to have url that look like:

      .com/category/name
      .com/category2/name
      .com/category/name2
      .com/name3

      I don't want to use WP as all my site is already built with regular html/php, and I've heard WP also takes a lot of resources, so I wouldn't want to install it just for the sake of having nice URLs.

      Yet I do acknowledge that it would be inefficient to code everything from scratch, so what's the best solution for me?
      there are many ways to do what you want done!

      so go to the pages you want in the category you like. get your pages and rename them to index.php or another name and put them in a category folder. each category main page will be index.php. So you can have a menu page and then sub menu pages!

      OK you create your folders and name them what you like:
      .com/category/
      .com/category2/
      .com/category/

      then have your php files in each folder!
      .com/category/index.php
      .com/category2/index.php
      .com/category/index.php

      the index.php in each category can have there own links for anything within that category folder!
      Signature
      {{ DiscussionBoard.errors[9067058].message }}

Trending Topics