我的 PHP 网站中有 htaccess。我想使用带有或不带有斜杠的 url。
下面的代码仅适用于尾部斜杠。
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)/$ $1.php [NC,L]
例如www.mydomain.com/index/ -- 有效 www.mydomain.com/index --
无效
如果有人知道我怎样才能在没有斜杠的情况下得到这个?
谢谢
我的 PHP 网站中有 htaccess。我想使用带有或不带有斜杠的 url。
下面的代码仅适用于尾部斜杠。
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)/$ $1.php [NC,L]
例如www.mydomain.com/index/ -- 有效 www.mydomain.com/index --
无效
如果有人知道我怎样才能在没有斜杠的情况下得到这个?
谢谢
你有这个规则:
RewriteRule ^(.*)/$ $1.php [NC,L]
如果您想匹配它,无论/
最终用途如何:
ErrorDocument 404 /not-found.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
将停止重新应用相同的规则,因为$1.php
这将是一个真实/有效的文件。
这就是我用类似的东西所做的
RewriteRule ^(.*)/?$ /$1.php [NC,L]
?
在 the 后面加上一个/
使其可选。
修复将是
RewriteRule ^(.*)/?$ $1.php [NC,L]