[英]Trailing slash causes 404, can I fix using htaccess?
The offending URLs are: 违规网址是:
The .htaccess rule I have for these types of URLs looks like: 我对这些类型的URL的.htaccess规则如下:
RewriteRule ^face/(.*)$ face.php?term=$1
What can I do to make both of these URLs to go to the same page? 如何使这两个网址转到同一页面,我该怎么办?
You can use this: 你可以用这个:
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.
第二行说:重定向从开始到跟踪的所有内容,并结束到那里的所有内容,没有尾随斜杠。
Put your own RewriteRule
in there (below that one, not above) so your normal redirect still works after the trailing slash was removed. 把你自己的
RewriteRule
放在那里(低于那个,而不是上面),这样你的正常重定向仍然可以在删除尾部斜杠后继续工作。
(this one will obviously work for /body/
too, and not only for /face/
. (这个显然适用于
/body/
,而不仅仅是/face/
。
I use this rule which is slightly modified to maintain any subfolder structure 我使用这个稍微修改的规则来维护任何子文件夹结构
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.