Forum

Thread tagged as: Question, Problem, Configuration

Switching file extensions (.htaccess file)

I am trying to swap the .php with a .html extension on all pages but when doing so some of Perch features stop working (the contact form doesn't output data to the backend).

Heres the script I've found to swap the extensions:

RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} (.).php
RewriteRule ^(.
).php $1.html [R=301,L]

RewriteCond %{THE_REQUEST} (.).html
RewriteRule ^(.
).html $1.php [L]

Heres the website: https://www.ashesintoglass.co.uk/ Running version 2.3.2

Any help would be great!

Samuel Marchant

Samuel Marchant 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you're redirecting rather than rewriting - is that really what you want to do?

Drew McLellan said:

It looks like you're redirecting rather than rewriting - is that really what you want to do?

Ahh I would prefer to rewrite but haven't had much experience with editing the .htaccess file, any tips?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try changing this:

RewriteRule ^(.).php $1.html [R=301,L]

to this:

RewriteRule ^(.).php $1.html [L]

Thanks Drew this has worked although the contact page after submitting the form is still throwing an error:

https://www.ashesintoglass.co.uk/order-process.php

(The requested URL /order-process.html was not found on this server.)

I can't change this page to .html extension as it wouldn't process the form, right?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If PHP is being parsed then it'll work whatever the extension. You need to pick one and stick with it though, else you'll keep running into consistency problems.

In the end I just wrote in the files I wanted to have a different extension and that works perfectly. Thanks for you help Drew.