Can't remove .php from website using htaccess. Dreamhost server - php

I am trying to remove the ".php" on my website. I have changed the .htaccess file based on the documentation provided in the dreamhost wiki to the following:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
However, this does not work on the site. For example this code does not work:
link
It shows the following error:
Not Found
The requested URL /jimmyvosler.com/public/about.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This works (but still displays the .php at the end, which is what im trying to fix):
link
I don't understand what is causing this, especially since the error even points to the correct place. Is there a setting I need to check on my admin tool?

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

Here is the solution for anyone else that has the same trouble. I added this to my .htaccess file. This solution came from dreamhost support and was linked from this website: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Try this:
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]

Related

Having trouble removing PHP extension

On my website I have been trying to remove the PHP extension's on every page; I am worried that I may interfere with the SEO and end up glitching the site.
I have tried alot of methods on the internet but none of them seem to be working ? Maybe I am doing something wrong, or it's an internal control panel error ?
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
No results from this or any others, advice ?
This has always worked for me:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
In one project here we used:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Which you could try as well

An "internal server error" aka 500 has perplexed me entirely - .htaccess slash php madness

I know what this error is, but I'm sure it has something to do with my recent change of .htaccess or something missing from it. I added a few lines of rewrite code to change "something.php" to "something" - it worked fine. When testing my website online for the last few stages of development, I wanted to see what type of errors I'll get by attempting to access folders, and files - 404, 403, 401 etc.
Lets get to the point! When I entered ....com/press or ....com/press.php it will take me to the page as expected. When I enter ...com/press/ I get a 500 error - yes it has a slash, but shouldn't I be getting a 404 error? I say this because the file press.php exists, but not the folder ...com/press/ - it doesn't even show my own custom error page!
After taking a look at what I put in this .htaccess file, I also want some additional help with .htaccess. Index should be index alone, the server shouldn't accept .php even if it is, if you know what I mean!
Thanks in advance
Code in .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
Modify your rule as:
ErrorDocument 404 default
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Index should be index alone, the server shouldn't accept .php even if
it is
You can use this so that if they using the php extension, it will redirect.
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /(.+)\.php
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)/?$ /$1.php [L,QSA]

how hide extension of my php files

I`m trying to hide my php files extension in my hosted server.i add following code segment in .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
but when i try, it is not working. also i tried to do the same thing in my localhost.it is also not working properly.
so do i have to make any other changes to work on it?
The best solution for this is to first:
1. Convert all your .html files to .php
2. Make a .htaccess to hide all known .php extensions
E.g:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
NOTE: If you already have the RewriteEngine on command on top of your .htaccess file, no need of writing it when making new commands.
This method yet is ineffective because when you access localhost/login.php, it would redirect to localhost/login.
So you must do that with php in the individual files!.
Use
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Remove .php extension is not working

I found a lot of tutorials and questions regarding to removing the .php extension in the URL. I have tried a lot of examples and until now it is still not working. This drives me crazy. I also want to put trailing slash at the end of the URL but first I would like to achieve this first. Currently I have tried this which is some of my solutions:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
and also this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Nothing is good. I am working in my laptop using windows 7, and using XAMPP. I simply created my .htaccess file and put it in localhost/myFolder. When I run in the browser, depending on my solution, (i) some times I got page not found, (ii) sometimes server internal error. Also when I run for example localhost/myFolder/index the URL will be redirected to localhost/index without myFolder. I wonder why is this happening and hope somebody can give me links or solutions because I tried so many of them. Thank you in advance.
The following works fine for me:
RewriteEngine On
RewriteBase /myFolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])/?$ $1.php [L]
Try this code in /myFolder/.htaccess for hiding .php extensin:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/myFolder/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
A solution for your problem:
Options +MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/myFolder/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I just replaced your - sign in multiviews and it started working on my localhost

Using .htaccess to URL rewrite on windows

I have have turned mod_rewrite on in a windows machine and created .htaccess in the root directory of my website, now after i wrote FAIL in it it gave me an internal server error then i replaced the code with this
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
I am trying to remove .php and make friendly URLs, when i am tring to load index without using .php it is giving me a 404 Not found error i have restarted the wamp server several times and the same problem. Can somebody help me here.
Thanks in advance
I have changed the .htaccess to this
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
and it worked just in case somebody faces the same problem
Remove the line RewriteCond %{REQUEST_FILENAME}.php -f. It is unnecessary.

Categories