Forum Moderators: phranque

Message Too Old, No Replies

Rewrite

         

empra6or

3:27 am on Mar 18, 2011 (gmt 0)

10+ Year Member



I am trying to hide the .php from my URLs. So, instead of
example.com/download.php
I want to be able to do
example.com/download

I am also trying to force www. For some reason this is not working. any help would be appreciated.This is what I have in my .htaccess file

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

jdMorgan

10:42 pm on Mar 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The rules are incorrectly ordered, and you can speed it quite up a bit:

Options +FollowSymlinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond $1 !\.(php|gif|jpe?g|pnf|ico|css|js)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ /$1.php [L]

Other changes for robustness and security.

Jim

g1smd

10:49 pm on Mar 28, 2011 (gmt 0)

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



Make sure too, that all of your internal links point to the URL that you want users to "see" and "use".