如果我使用许多html文件和一个php文件,如何删除.html和php文件扩展名

I used the following .htaccess code for the html files:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

and it worked well.

and then I tried to use a code for both them (html and php) like this:

RewriteEngine on

RewriteBase /
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L]

it did not work. because my html files are links that can be clicked which works but the php file is not a link. its an external file that has phpmailer which sends an email when the user click the send button. this is my php file (contact.php):

<?php

if(isset($_POST['submit'])){

          require 'PHPMailer\class.phpmailer.php';
          require 'PHPMailer\class.smtp.php';
          require 'PHPMailer\PHPMailerAutoload.php';
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'mygmail@gmail.com';                 // SMTP username
    $mail->Password = 'mypassword9876543210';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom($_POST['email']);
    $mail->addAddress('mygmail@gmail.com');     // Add a recipient
    $mail->addReplyTo($_POST['email']);

    //Attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $_POST['subject'];
    $mail->Body    = $_POST['msg'];
    $mail->AltBody = $_POST['subject'];

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}

when a user clicks this button:

<div class="text-center">
  <button type="submit" class="btn btn-start-order" name="submit">Send 
    Message</button>
</div>

the php file sends the email, but it also shows contact.php in url. How Can I get rid of website.com/contact.php to show and just have website.com/contact after the message is sent. Sorry about the long question. Thank you.

Try this in your .htaccess to remove the .php extension

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

EDIT: Try this instead, It maybe what you're looking for and it may not be, but I hope it helps.

RewriteEngine On

RewriteBase /

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