斜杠末尾导致404,我可以使用htaccess进行修复吗?

编程入门 行业动态 更新时间:2024-10-08 19:46:00
本文介绍了斜杠末尾导致404,我可以使用htaccess进行修复吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有问题的URL是:

  • (不起作用) alltheragefaces/face/surprised-wut/
  • (Works) alltheragefaces/face/surprised-wut
  • (Doesn't work) alltheragefaces/face/surprised-wut/
  • (Works) alltheragefaces/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进行修复吗?

本文发布于:2023-11-02 07:08:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551703.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   末尾   可以使用   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!