斜杠末尾导致404,我可以使用htaccess进行修复吗? [英] Trailing slash causes 404, can I fix using htaccess?

查看:69
本文介绍了斜杠末尾导致404,我可以使用htaccess进行修复吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题的URL是:

  • (Doesn't work) http://alltheragefaces.com/face/surprised-wut/
  • (Works) http://alltheragefaces.com/face/surprised-wut

我对这些类型的URL的.htaccess规则如下:

The .htaccess rule I have for these types of URLs looks like:

RewriteRule ^ face /(。 *)$ face.php?term = $ 1

如何使这两个URL都进入同一页面? / p>

What can I do to make both of these URLs to go to the same page?

推荐答案

您可以使用以下代码:

 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)/$ /$1 [L,R=301]

第一行说:如果它不是目录(因为后跟斜杠才有意义)。第二行说:重定向所有内容,从开始到结尾的斜线,再到结尾的所有内容,都没有结尾的斜线。

The first line says: "if it's not a directory" (because then a trailing slash would have meaning). The second line says: redirect everything from start to the trailingslash and end to everything that was in there, without the trailing slash.

放入您自己的 RewriteRule 在那里(在那个下面,而不是上面),因此在删除斜杠后,您的常规重定向仍然有效。

Put your own RewriteRule in there (below that one, not above) so your normal redirect still works after the trailing slash was removed.

显然也可以用于 / body / ,而不仅可以用于 / face /

(this one will obviously work for /body/ too, and not only for /face/.

这篇关于斜杠末尾导致404,我可以使用htaccess进行修复吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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