Forum

Thread tagged as: Question

.htaccess issue - Internal Server Error

I'm using Perch, and I'm trying to use htaccess to hide the .php extension.

Here's my htaccess file

RewriteEngine On

   # Redirect to PHP if it exists.
    # e.g. example.com/foo will display the contents of example.com/foo.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f 
    RewriteRule ^(.+)$ $1.php [L,QSA]

This works quite well = if I have a file called about.php, when I visit https://local.domain.com/about, about.php displays correctly. But if I add a trailing slash (https://local.domain.com/about/) I get an Internal Server Error. Any suggestions?

Update - Diagnostic:

Perch: 2.8.29, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.29), assets (2.8.29), categories (2.8.29), perch_blog (5.0), perch_events (1.9.2), perch_forms (1.8.3), perch_shop_orders (1.0), perch_shop_products (1.0), perch_shop (1.0.1), perch_members (1.5), perch_twitter (3.5.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_forms', 'perch_members', 'perch_shop', 'perch_events', 'perch_twitter', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /PATH_TO/perch
PERCH_CORE: /PATH_TO/perch/core
PERCH_RESFILEPATH: /PATH_TO/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: local.include-ed.org.uk
DOCUMENT_ROOT: /PATH_TO
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Thanks.

Paul Bell

Paul Bell 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is it trying to route you to about/.php ?

I guess it could be. How would I tell?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could try modifying the pattern to not include a trailing slash in the replacement.

RewriteRule ^(.+)/?$ $1.php [L,QSA]

Thanks, Drew - I am a .htaccess numpty. The same thing still happens unfortunately - works fine with no trailing slash, but error with a trailing slash.

RewriteEngine On

# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)/?$ $1.php [L,QSA]
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. The Perch solution to this is to use Runway, which has routing built in.

OK - thanks, Drew.