2

我刚开始学习正则表达式,我就是想不通。如果 URL 不包含扩展名,我需要在 URL 末尾强制使用斜杠。

所以要更清楚:

example.com/test/ stays the same.
example.com/test.php stays the same.
example.com/test becomes example.com/test/     (See the last slash at the end)

有谁知道如何解决这个问题?

4

2 回答 2

1

把它放在你的 .htaccess 上:

Options +FollowSymlinks
RewriteEngine on

RewriteBase /
RewriteRule ^/test$  /test/ [L]
于 2013-09-10T08:35:49.460 回答
0

奇怪的是我偶然发现了一个解决方案:

RewriteCond %{REQUEST_URI} /+[^\.]+$ 
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

起初它在每一行的末尾添加了一个斜杠,即使它以 .php 结尾,但现在它可以工作了,很奇怪。

于 2013-09-11T07:14:21.233 回答