views:

102

answers:

4

Is there a way to mask the URL extensions for pages on my website with PHP? Example: http://home/subfolder instead of http://home.subfolder.php

+2  A: 

Apache httpd's mod_rewrite can rewrite the URL transparently on the server side and let you use any URL you like.

Ignacio Vazquez-Abrams
A: 

Place the following in the .htaccess file in the root of your website

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteCond %{SCRIPT_FILENAME} !-d
   RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
Cirrostratus
A: 

As others have stated, this is done with mod_rewrite if you're on an Apache-enabled server. Various questions have been asked similar to this:

Related:

  1. How to hide the .html extension with Apache mod_rewrite
  2. Removing .php with mod_rewrite
Jonathan Sampson
+1  A: 

Yes, it's possible, although it has nothing to do with PHP.

You'd have to create a file named .htaccess on the root of your webserver (if it does not yet exist). For instance, if you'd want to silently redirect users from /page/software/ to index.php?page=software, you'd use:

RewriteEngine on 
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

The initial part (^page/([^/\.]+)/?$) is a regular expression. If you're not sure how to use them, give us an example of what you're trying to do, and we can help.

David Chouinard