Southperry.net
Getting rid of file extensions such as .html and .php - Printable Version

+- Southperry.net (https://www.southperry.net)
+-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14)
+--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58)
+--- Thread: Getting rid of file extensions such as .html and .php (/showthread.php?tid=67196)



Getting rid of file extensions such as .html and .php - icephoenix21 - 2013-10-08

Hello, I'm in need of some help for a course assignment. I've done all of the major work for this web design assignment, except for the following part,

"Build your site so the URLs for each page are in this easy-to-type format, and users don't even know they're accessing PHP files"

I realize that if I have each page in it's own directory, and labeled as index.php, then the file can be accessed without the php extension (example: "mysite.com/lab4/page1" ). However, the problem with that is when you type it in, it simply redirects you to "mysite.com/lab4/page1.php".

I'm fairly certain that the instructor wants us to have it so that the web page displays no .php or .html extension.
I've tried to google search around a bit, and it seems that there is a php code that deals with having an htaccess file, as well as this string of coding:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]

Is there any simpler way to do this? The class really hasn't gotten into much php at all, so this seems a bit advanced for the classwork at the moment.


Getting rid of file extensions such as .html and .php - Collofit - 2013-10-09

There is no other way than modrewrite that I'm aware of, so yes you have to use a htaccess file.

Some tips for beginners: http://corz.org/serv/tricks/htaccess2.php

Documentation: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html


Getting rid of file extensions such as .html and .php - Eos - 2013-10-09

.htaccess files have nothing to do with php, they're control modules for apache.

The
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Should really be all you need for most cases. It doesn't have to be in an .htaccess file either, you can put it directly in your httpd.conf at any level if you want it to effect all sites, or site wide to a specific site regardless of folder depth. htaccess files are overrides to the default conf.