Hello

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

Have you tried using REQUEST_URI instead of REQUEST_FILENAME ?

Try:

RewriteEngine On
RewriteBase /~jn/
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^([^\.]+)/?$ /~jn/$1.php [NC,L]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.