I am not sure what category to put this in. I have a question about .htaccess

what I am wanting to do is remove all .php extentions from all files on a website
so www.domain.com/contact.php will become www.domain.com/contact

So my .htaccess file which I have in my public_html folder is

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

Now my issue is I am wanting to use this on a site that will not have a domain name setup with it. So the site will only be reached via a IP address like so
http://xxx.xxx.xxx.xxx/~jn (ip address x'ed out for privacy reasons)

and what seems to happen is when I try to go for example to

http://xxx.xxx.xxx.xxx/~jn/contact I get a 404 error
however when I go to
http://xxx.xxx.xxx.xxx/~jn/contact.php the page works of course without having the .php extention removed.

I tried putting my .htaccess on a website that I have a domain name setup/pointed to and it seems to work. So does .htaccess not work with just an IP address or how would I modify the above code so it would work when using an ip address to view a page and wanting to remove the .php extention on the files

thanks all

Edited by jayreis: n/a

6 Years
Discussion Span
Last Post by hielo

Have you tried using REQUEST_URI instead of REQUEST_FILENAME ?


RewriteEngine On
RewriteBase /~jn/
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^([^\.]+)/?$ /~jn/$1.php [NC,L]
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.