Forum Moderators: coopster

Message Too Old, No Replies

removing the .php from pages

Hi i am trying to remove the .php from web pages

         

lonestar32

12:07 pm on Sep 24, 2007 (gmt 0)

10+ Year Member



Hi i am new here we run a website called www.example.com and i was wondering if it is possible to remove the .php from the end of a address

For example www.example.com/newsinbrief.php, it would be nice it I could have it as www.example.com/newsinbrief

Is this possible does anyone know how to do it and if so where i could look for the code advise etc.

Any help you could give me would be very much appreciated.

Thanks in advance for any help

Regards

Tim

[edited by: dreamcatcher at 12:10 pm (utc) on Sep. 24, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]

PHP_Chimp

12:12 pm on Sep 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Easy to do with .htaccess.

Either use -
DefaultType application/x-httpd-php

Then you can call pages with no extension i.e. expample.com/mypage
As this tells the server to treat anything without an extension that it recognises as a php page.

or use -
AddType application/x-httpd-php .html

This tells php to parse anything with a .html extension as well as all of its default extensions. With this method you can choose whatever extension you want to use.
i.e. the UK law society use .law extensions to there pages

[edited by: PHP_Chimp at 12:13 pm (utc) on Sep. 24, 2007]

lonestar32

12:14 pm on Sep 24, 2007 (gmt 0)

10+ Year Member



Hi thanks for all of your help forgive me for being think but whereabouts in the page does the code go bit of a beginner lol

PHP_Chimp

12:29 pm on Sep 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that you are running on an Apache server then you will have the ability to create .htaccess files. These are nothing to do with PHP, they are a script that runs on the server, before PHP ever sees anything.

You may well be better going to [webmasterworld.com...] as this question has probably been answered over there.

In brief -
You create a text file called .htaccess. The file name must start with a . so windows may object if you try to create the file.

Place whatever line of code you choose into the htaccess file and upload it to the server. Usually at the very root of your directors as Apache searches all directories from the root up for htaccess files and they work for all directories above there location.

You may need to turn on the rewrite engine first, you may need other options in there to make it work. It depends on the server setup and what the admin allows you to do if you are on a shared server. Also htaccess can kill you site, well make it issue 500 errors, so check that it works before you down your website.

HarryM

12:42 pm on Sep 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An easy way to produce a .htaccess file is to create it using Notepad or other editor as htaccess.txt. Upload it to the site, and then rename it to .htaccess.