dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
815
share rss forum feed


bbchris2nd
Joke Factory

join:2010-09-03
Australia

Website Link

I have an html page for Contact Us named contactus.html. When I click on the link Contact Us it displays on address bar as www.example.com/contactus.html. How can I remove the html extension when I click on Contact Us that will display www.example.com/contactus

Just a newbie here.

TIA.
--
Be brave even if you're not. Pretend to be. No one can tell the difference.



cdru
Go Colts
Premium,MVM
join:2003-05-14
Fort Wayne, IN
kudos:7

Multiple different ways to get an extensionless URL. Depending on the what you are using for the server, you can use URL rewriting so that the server internally adds the .html (or .aspx, .php, etc depending on type of site). We'd need to know what type of system it's being ran on (apache, nginx, IIS, etc).

A poorman's way of doing it is to put contactus.html inside of the directory of /contactus and rename it index.html. Then ensure that index.html is in the list as a default document for a directory. When www.example.com/contactus is requested, the directory contactus is checked to see if it exists, and if it is is there a default document (index.html) located in side of it. You're address bar URL will change to www.example.com/contactus/ which isn't exactly what you asked for, but it's still a semi-extensionless URL.



sbconslt

join:2009-07-28
Los Angeles, CA
reply to bbchris2nd

If using Apache, this is a built in part of its content negotiation logic called MultiViews. You might have to enable it at the config.
--
Scott Brown Consulting



Ashke
Flips page and continues reading
Premium
join:2007-09-11
Minneapolis, MN

2 edits
reply to bbchris2nd

Ok... If you are using the very very basic language, HTML... This is how it works:

Your WWW directory (where you store your site

index.html
filename.html
contactus.html
 

do this...:

    •Create a folder entitled "contactus" (if you are using linux or unix distros, then I strongly recommend you to keep it all in lowercase because the Unix/Linux are pretty inane when it comes to case-sensitivity)
    •Put contactus.html into the directory (folder) "contactus"
    •Rename contactus.html to index.html


Your directory should then look like this:

<dir> contactus
        -index.html
index.html
filename.html
 
note... <dir> denotes directory (aka: folder)

To do it the PHP's way... Gotta make sure you have PHP installed ;)

where you want to put this... I recommend putting it in a separate page solely for navigation, but wherever works for you.
<?php
    //Declares Variables
    $nav = '';
 
    $nav .= '<a href="/?page=contactus">Contact Us</a>';
?>
 

This will be on your next page... It loads the next page
<?php
    
    $default = './index.php'; //Default page
    $error =  './error404.php';
    
    //This will pull whatever string is after yoursite.com/?page=
    $tempPage = isset($_GET['page']) ? $_GET['page'] : $default;
    
    
    //This if / else functions checks to see if $tempPage is the same as $default or 'home'
    //Then it will process the instructed codes
    if ($tempPage == $default){ // Checks to see if $tempPage contains the same string as $defualt or 'home'
        
    }
    else if($tempPage == 'home'){
        $tempPage = './' . $tempPage . '.php';    
    }
    
    else {
        $tempPage = './' . basename($tempPage) . '.php'; //Gets the page name only, and no directories.
    }
    
    
    //require($tempPage); //For use when the codes below fail
    if (!file_exists($tempPage))    { //Checks if the file doesn't exist
        //File does not exist...
        //Assigning $error to $page
        $page = $error;
    }
    else{
        $page = $tempPage; //Assigns page from $tempPage to $page
    }
    require($page); //And now it's on your page!
?>
 

You don't have to use 'page' as the URI, but it's one of the suggestions... You can use anything as long as it doesn't contain any special characters.... Actually I rescind this last statement, but it's very picky on what special characters you use.

I hope this helps...

--
-Ashke


cdru
Go Colts
Premium,MVM
join:2003-05-14
Fort Wayne, IN
kudos:7

said by Ashke:

Ok... If you are using the very very basic language, HTML...

If he's using a "very very basic language, HTML", why give him a PHP "solution"? PHP is just adding an additional layer of complexity where it's not needed, and may not even be an option.

The three most dominate web servers (Apache, nginx, IIS) have ways of handling extensionless URLs that I think most would consider better solutions then a PHP page acting as a proxy.

The main reasons for extensionless URLs SEO, appearance, and technology agnostic. SEO is arguable as to it's importance, and using a ugly URL is almost universally regarded as a better idea than serving up content specifically based on query string. Appearance is pretty obvious, and a query string is always uglier than just about anything else. And as far as not being tied to one technology or another by not having an extension, I don't think that's really an issue there with this particular site.

Create a folder entitled "contactus" (if you are using linux or unix distros, then I strongly recommend you to keep it all in lowercase because the Unix/Linux are pretty inane when it comes to case-sensitivity)

Unix/Linux are the operating systems and have nothing to do with serving up files. And I'd argue that the *nix webservers (Apache, nginx, and similar) are are the opposite of inane when it comes to case sensitivity. index.html is different than InDeX.HtMl. It's IIS and servers that have case-insensitivity enabled that dumbly serve up files regardless of case.