Jelmer Holtes
Jelmer Holtes

Reputation: 73

Rewrite URL with .htaccess to hide PHP extension

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

Upvotes: 1

Views: 29648

Answers (4)

Lakshman Kambam
Lakshman Kambam

Reputation: 1618

try this.. it works! :)

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

Upvotes: 0

Jacob Pollack
Jacob Pollack

Reputation: 3751

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:

  1. Left click WAMP icon
  2. Apache
  3. Apache Modules
  4. Left click rewrite_module.

Upvotes: 6

shaz3e
shaz3e

Reputation: 334

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]

Upvotes: 5

Irshad Khan
Irshad Khan

Reputation: 6046

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

Upvotes: 0

Related Questions