如果的.htaccess URL不与扩展名结尾,在末尾添加斜线 [英] .htaccess if url not ends with extension, add slash at the end

查看:127
本文介绍了如果的.htaccess URL不与扩展名结尾,在末尾添加斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习正规的前pressions,我实在不明白这一点。我需要强制斜线的URL末尾,如果它不包含扩展名。

I just started learning regular expressions and I just can't figure this out. I need to force a slash at the end of an URL if it not contains an extensions.

因此​​,为了更清楚:

So to be more clear:

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)

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

Anyone who knows how to fix this?

推荐答案

自叹不如我刚刚发现意外的解决方案:

Strange enough I just found a solution by accident:

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

首先,添加在每行的末尾斜线,即使它与.PHP结束,但现在它的作品,奇怪的是。

At first it added a slash at the end of every row, even which ended with .php but now it works, strangely enough.

这篇关于如果的.htaccess URL不与扩展名结尾,在末尾添加斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆