0

I have a fully working site with a number of various contact forms.

I hid the .php at the end of each pages name in the URL using the .htaccess file but when I do this the contact form breaks. Is there another way of hiding these suffixes?

Many thanks

anubhava
  • 664,788
  • 59
  • 469
  • 547
  • Show your .htaccess by editing question. Is your form using `POST` method? – anubhava Dec 22 '20 at 19:44
  • Yeah using POST. Below is the htaccess file: RewriteEngine on RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC] RewriteRule ^ /%1 [NC,L,R] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [NC,L] – Sam Donaghy-Bell Dec 22 '20 at 19:47
  • Please "edit your question" (as anubhava suggested) to add the contents of your `.htaccess` file. Posting unformatted code (especially regex) in a comment can omit special characters from display and render the code sample useless. – MrWhite Dec 24 '20 at 14:23
  • Also, how is the "contact form" being called, what's the end-point? – MrWhite Dec 24 '20 at 14:23

1 Answers1

2

You should skip POST requests from redirect rules like this:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Modern browsers support HTTP status code 308 that doesn't change a POST request to GET, so you may use first rule as:

RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=308,NE,L]
anubhava
  • 664,788
  • 59
  • 469
  • 547