Rewrite URL with .htaccess to hide PHP extension - php

I've a question, I'm developing a webservice for a specific app.
Last week I transferred my back-up from server1 to server2, since that moment my .htaccess won't work anymore.
The url for my webservice is:
http://apps.holtesdesign.nl/inholland/apiv0/
This url works fine, to load the bugreport module:
http://apps.holtesdesign.nl/inholland/apiv0/bugreport.php
But the url was supposed to be:
http://apps.holtesdesign.nl/inholland/apiv0/bugreport
When you'll open the last url, you'll see that it will result in an internal server error.
Do you know how it's possible?
My .htaccess looks like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The server is running on CentOS, and I've already checked if mod_rewrite is functioning...
I hope you can help me guys!
Cheers,
Jelmer

This will fix it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
If it doesn't work correct the settings of your Wamp Server:
Left click WAMP icon
Apache
Apache Modules
Left click rewrite_module.

This will hide the trailing slash and hide .php in root & sub directories.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

Working Concept for me:
# Options is required by Many HostSevice
Options +MultiViews
RewriteEngine on
# For .php & .html URL's:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Use this code in Root folder of your website in .htaccess File : Example
offline - wamp\www\YourWebDir
online - public_html/
Important Note : If it doesn't work correct the settings of your Wamp
Server: 1) Left click WAMP icon 2) Apache 3) Apache Modules 4) Left
click rewrite_module

try this.. it works! :)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Related

RewriteRule for Subdirectory

I'm new to the Rewrite mod and have been looking over it for the last few days but I am still struggling to get this to work.
I already have a .htaccess file in the root directory that is forcing the secure version of the site and hiding extensions, so that https://www.example.com/help.php goes to https://www.example.com/help
My problem is my admin tool at https://www.example.com/admin
I'd like it to work so that a page like list.php appears as https://www.example.com/admin/list but no matter what I trial, it always either breaks or redirects to the root index file.
Here my root .htaccess file
FallbackResource /index.php
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Can anyone help with what I should add to the admin directories .htaccess file, it's a Redhat server if that helps.
Thanks in advance for any help.

.htaccess for wampserver 3.0.6 not working

I am currently using Wampserver 3.0.6 to build this website. I finished the whole thing but the URL re-writing is a bit of a pickle for me.
I have put the .htaccess file in the root directory of my website files(not in the root directory of Wampserver).
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Its not showing me the output I desire. I turned on the re-write mode in Apache httpd.conf file still no success. What am I doing wrong?
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
This worked perfect for me.

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

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]

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