htaccess的麻烦隐藏文件扩展名,并迫使斜杠斜杠、文件扩展名、麻烦、htaccess

2023-09-02 01:06:55 作者:每一天,为明天

当我键入domain.com/page.php它不会自动更改为domain.com/page/。此外,对于在子目录中的网页,如果我跟着一个链接到domain.com/sub/1/~~V一切都很好,但如果我在浏览器中键入它重定向到domain.com/1~~V /

When I type domain.com/page.php it doesn't automatically change to domain.com/page/. Also, for the pages in subdirectories, if I follow a link to domain.com/sub/1/ everything is fine, but if I type it in the browser it redirects to domain.com/1/

这是我在.htaccess

This is what i have in .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/$ $1.php

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

任何想法我应该做的子目录和根目录htaccess的文件吗?我在这个新的。

Any ideas what I should do to htaccess files in the subdirectories and root directory? I'm new at this.

推荐答案

更​​改规则的顺序。

试试这个:

RewriteEngine on

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?[^/])$ /$1/ [R=301,L]

# .php ext hiding
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]