Forum Moderators: coopster

Message Too Old, No Replies

getting rid of the ".php" in url

multiple ways of doing it: which one do you use?

         

alkuma

6:07 am on Jan 7, 2008 (gmt 0)

10+ Year Member



I have this site, which uses php for server side scripting.
Now, I don't know which direction the world would move tomorrow, and I wouldn't like the url's to change if I change the server side programs.
Apart from that, I don't want the visitors to know I'm using php.

I could think of multiple ways of doing this

1. for each page, have a separate directory, and keep an index.php there. That way people only type http://example.com/section1 instead of http://example.com/section1.php. However, in that case, http://example.com/setion1.php would also work - I don't want it to work.

2. using some apache options(mod_rewrite?) let extension less file names be assumed as being php scripts.

What approach would you recommend? Or is it a bad idea to begin with?

lammert

10:33 am on Jan 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



All my URLs end in ".HTML" and I use settings in the httpd.conf config file to let PHP parse them when necessary. This can be done (at least in Apache 2.2) with the following in httpd.conf:

<Directory "/your-directory-tree-to-site">
AddHandler php-script .html
</Directory>

With changing settings I transformed one static HTML file via SSI to currently PHP without the visitors and search engines ever seeing any changing in the URLs.

alkuma

10:59 am on Jan 7, 2008 (gmt 0)

10+ Year Member



Thanks lammert, that would get rid of the ".php's". Would definitely use this in absence of something better.
Any other options? ie, could we get rid of extensions totally? ie http://example.com/section1 instead of http://example.com/section1.html?

Receptional Andy

11:49 am on Jan 7, 2008 (gmt 0)



You can use Apache's content negotiation [httpd.apache.org] to do this very easily, although multiviews can cause it's own problems!

dave_c00

12:01 pm on Jan 7, 2008 (gmt 0)

10+ Year Member



An .htaccess command is what I would use...

Within this you can put:

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

Using this example.php should run when you put example.html as the address.

jatar_k

2:05 pm on Jan 7, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> I don't want the visitors to know I'm using php

you may want to change this setting in php.ini as well then

[php.net...]