我尝试使用以下代码在我的网站上强制使用斜杠:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
它有效但当我去一个应该抛出404的页面时,它会将我重定向到www.domain.com/404.shtml
,这会进入重定向循环。
我已从htaccess中删除了上述代码,但仍然需要强制执行斜杠。
我的完整htaccess重写规则:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^services(/)*$ ./services.php
RewriteRule ^contact(/)*$ ./contact.php
RewriteRule ^about(/)*$ ./about.php
RewriteRule ^work(/)*$ ./work.php
RewriteRule ^work/prima-healthcare(/)*$ ./my-work/primahc.php
RewriteRule ^work/medical-studies-europe(/)*$ ./my-work/mse.php
RewriteRule ^work/rowley-village-nursery(/)*$ ./my-work/rvn.php
问题是:如何在不影响我的清洁URL重写规则的情况下强制执行尾随斜杠