How do I use URLs without page extensions?

shaurya gupta October 17, 2012

How do I use URLs without page extensions? For example, MakeUseOf has an Answers ask page which is // Now, this page is actually .php I think, and whenever I try to make my own website I have to use the .php extension to bring up a page. But when I go to the MakeUseOf link, that extension is not needed. How can I make my website do that?

  1. iohm Tan
    October 17, 2012 at 11:14 am

    I'll check this post from time to time. I love what I"m learning here. :)

  2. Chew Jian Yue
    October 17, 2012 at 9:46 am

    Rename the php file or other files to "index.php" (default name to direct the server, to the location without any extension ".php".

  3. James Bruce
    October 17, 2012 at 7:29 am

    A fairly complicated question, but I'll make the answer simple: you set up redirects using your web server software, typically Apache . This is done in a file called .htaccess in the root of your public_html directory.

    For example, this site runs on WordPress, which uses an .htaccess file similar to this:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    What that is to take anything put in the URL, and redirect it to index.php, which handles all the requests and builts the site dynamically. So when you type in /answers/urls-page-extensions/, it sends that index.php which looks for a post called "urls-page-extensions", and builds the post template using that ID. There isn't *actually* a page on our server called urls-page-extensions; it's all dynamic.

    But basically, you need to look up about htaccess rewrite rules.

    Or, just install a CMS like WordPress to handle all this for you. Manually rewriting rules for millions of static files is just silly.

    • Justin Pot
      October 17, 2012 at 1:15 pm

      Listen to this guy: he's the only one here who manages in its entirety. He's also a jerk, but he's still right.

    • shaurya gupta
      October 17, 2012 at 1:21 pm

      thanks man....worked for can i make my site with wordpress?

  4. Sabby Kutty
    October 17, 2012 at 6:21 am

    grt i learnt something from here!!

  5. Drew Butler
    October 17, 2012 at 3:09 am

    Two answers to your question can be found here:

    Both answers are correct it just depends on your current site structure and host as to which one will work best. Make sure to read all comments on that page. Hopefully this is helpful :)

  6. Bruce Epper
    October 17, 2012 at 1:43 am

    Set the default page on the web server. For example, you can set the default page to 'index.php' which will use the index.php page if nothing is specified after the trailing slash. Most servers will allow you to configure this as a list of pages to look for in a prioritized order (index.php first, then index.htm, index.html, etc). If you are using Apache, you can modify the httpd.conf file to include the line: DirectoryIndex index.php index.jsp index.htmlThis would cause the server to first search for the index.php file in the directory and use that if it exists. If it doesn't exist, it will continue by looking for index.jsp and finally index.html.

    • Deekshith Allamaneni
      October 17, 2012 at 2:17 am

      Yes, I agree with your answer.

    • James Bruce
      October 17, 2012 at 7:25 am

      That doesn't actually do anything other than define a default page though.

    • Dimal Chandrasiri
      October 17, 2012 at 7:37 am

      I don't think this would do for the whole website.! it would only make the index the default page. others would remain the same!

    • Ahmed Khalil
      October 17, 2012 at 9:35 am

      clear answer thanks for that

      • Harry Barnes
        October 17, 2012 at 1:05 pm

        that should work, i have just tried it

    • Harshit Jain
      October 17, 2012 at 2:39 pm

      I was also unable to understand the reason for that. Thanks for your answer. I am going to try it on my site.

Ads by Google