.htaccess 仅向.php文件扩展名添加斜杠

.htaccess 仅向.php文件扩展名添加斜杠,.htaccess,redirect,mod-rewrite,url-rewriting,friendly-url,.htaccess,Redirect,Mod Rewrite,Url Rewriting,Friendly Url,我的htaccess代码在所有URL的末尾添加了一个斜杠,但我只希望它在以.php文件扩展名结尾的文件中添加斜杠。我该怎么做 我的密码: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !^\/(.*?)\/$ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^

我的htaccess代码在所有URL的末尾添加了一个斜杠,但我只希望它在以.php文件扩展名结尾的文件中添加斜杠。我该怎么做

我的密码:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

你能试试下面的吗。仅使用显示的样本编写。请确保在测试URL之前清除浏览器缓存

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.php$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/seo$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

我将为这个问题打开另一个线程。你已经回答了我的问题。@ardacar,当然,干杯,学习愉快。