.htaccess 如何让htaccess区分文件和ID

.htaccess 如何让htaccess区分文件和ID,.htaccess,.htaccess,因此,在代码的第一部分,我只是将http转换为https。我的目标是在不使用.php的情况下使用URL,但在我的旧代码中,我遇到了一个问题,如果我这样做了,它会被用作我的service.php页面的id。所以如果使用https://example.com/contact就像是https://example.com/serve.php?id=contact但我希望它能像https://example.com/contact.php但另一方面,我希望不是方向或文件的ID仍然可以作为ID使用。我的旧代

因此,在代码的第一部分,我只是将http转换为https。我的目标是在不使用
.php
的情况下使用URL,但在我的旧代码中,我遇到了一个问题,如果我这样做了,它会被用作我的service.php页面的id。所以如果使用
https://example.com/contact
就像是
https://example.com/serve.php?id=contact
但我希望它能像
https://example.com/contact.php
但另一方面,我希望不是方向或文件的ID仍然可以作为ID使用。我的旧代码是

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d # not an existing dir
RewriteCond %{REQUEST_FILENAME} !-f # not an existing file
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f # and page.php exists

# redirect to the physical page
RewriteRule ^(.*)$ $1.php [L]

# otherwise, redirect to serve.php
RewriteRule ^ /serve.php [L]

RewriteRule ^(\w+)$ ./serve.php?id=$1

您可以在站点根目录中使用这些规则。htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f

    RewriteRule ^(\w+)$ ./serve.php?id=$1

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

上帝保佑你,终于有人不报告我的副本,但真正的帮助我了。继续这样下去!
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# skip rules below this for files and directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]


# rewrite to the physical php page
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# otherwise, redirect to serve.php
RewriteRule ^/?$ serve.php [L]

RewriteRule ^(\w+)/?$ serve.php?id=$1 [L,QSA]