Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide .php extension in .htaccess [duplicate]

Tags:

php

.htaccess

Possible Duplicate:
Remove .php extension with .htaccess

I'm trying to hide the .php file extension but for some reason can't get it to work. My latest attempt was the following:

<IfModule mod_rewrite.c>    RewriteEngine on    RewriteRule ^folder/([a-zA-Z_\-0-9]+)/?$ /folder/$1.php </IfModule> 

I have tried many different variances of code I have found online but still no luck. The .htaccess file is placed within the root directory.

like image 414
adamhuxtable Avatar asked Dec 03 '11 22:12

adamhuxtable


People also ask

How do I remove page file extension from URL?

The . html extension can be easily removed by editing the . htaccess file.


1 Answers

I've used this:

RewriteEngine On  # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]  # Redirect external .php requests to extensionless URL RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]  # Resolve .php file for extensionless PHP URLs RewriteRule ^([^/.]+)$ $1.php [L] 

See also: this question

like image 154
ryanve Avatar answered Sep 21 '22 23:09

ryanve