Oct172012

How do I use URLs without page extensions?

shaurya gupta asks:

How do I use URLs without page extensions? For example, MakeUseOf has an Answers ask page which is http://www.makeuseof.com/answers/ask/. 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?


Browser: Chrome 22
System: Windows
Tagged: , , ,

Comments for this Question are closed.

If you are looking for help, please ask a new question here.

We will be happy to help you!

6 Answers -

0 votes

Bruce Epper

October 17, 2012

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

Yes, I agree with your answer.

October 17, 2012
James Bruce

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

October 17, 2012
Dimal Chandrasiri

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!

October 17, 2012
Ahmed Khalil

clear answer thanks for that

October 17, 2012
Harry Barnes

that should work, i have just tried it

October 17, 2012
Harshit Jain

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

October 17, 2012
0 votes

Drew Butler

October 17, 2012

Two answers to your question can be found here: http://www.sitepoint.com/forums/showthread.php?818273-Not-displaying-html-extension-when-viewing-web-pages

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 :)

0 votes

Sabby Kutty

October 17, 2012

grt i learnt something from here!!

0 votes

James Bruce

October 17, 2012

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

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

October 17, 2012
shaurya gupta

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

October 17, 2012
0 votes

Chew Jian Yue

October 17, 2012

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

0 votes

iohm Tan

October 17, 2012

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