Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the .php extension with mod_rewrite

I want a mod_rewrite rule set, so I can refer to a page without the .php extension, but have that rewritten to include the .php extension. This will be running on a 1&1 server.

Are there any good references so I can learn more myself?

like image 555
James Avatar asked Feb 05 '11 16:02

James


People also ask

What is mod_rewrite used for?

mod_rewrite lets you create all sorts of rules for manipulating URLs. For example, you can insert values pulled from the requested URL into the new URL, letting you rewrite URLs dynamically.

What is mod_rewrite?

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern.


1 Answers

RewriteEngine On RewriteRule something something.php [L] 

http://example.com/something will be handled as if it was a request for something.php

To redirect all requests that are not a physical file to the same name but with .php:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule (.*) $1.php [L] 
like image 192
Dan Grossman Avatar answered Sep 17 '22 13:09

Dan Grossman