Php .htaccess隐藏文件扩展名并强制使用尾部斜杠时出现问题
当我键入domain.com/page.php时,它不会自动更改为domain.com/page/。此外,对于子目录中的页面,如果我跟随指向domain.com/sub/1/的链接,一切都很好,但是如果我在浏览器中键入它,它将重定向到domain.com/1/ 这是我在.htaccess中的内容Php .htaccess隐藏文件扩展名并强制使用尾部斜杠时出现问题,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,当我键入domain.com/page.php时,它不会自动更改为domain.com/page/。此外,对于子目录中的页面,如果我跟随指向domain.com/sub/1/的链接,一切都很好,但是如果我在浏览器中键入它,它将重定向到domain.com/1/ 这是我在.htaccess中的内容 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteR
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]
我应该如何访问子目录和根目录中的文件?这方面我是新手。改变规则的顺序 试试这个:
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]