尾部斜杠给出内部服务器错误 [英] trailing slash gives internal server error

查看:43
本文介绍了尾部斜杠给出内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在末尾添加了斜杠,我希望我的所有页面都能正常工作

I want all my pages to work if the user added a trailing slash in the end or not

以下行有效

RewriteRule ^index/page/([0-9]+)/?$ /cmstut/index.php?page=$1 [QSA,L]

但是下面这行导致内部服务器错误,这是最后一行这是应该重写所有其他没有联系页面、关于我们页面或索引页面等属性的页面的行

but the the following line cause an internal server error, It's the last line That's the line that should rewrite all other pages which have no attributes like the contact page, about us page or index page

RewriteRule ^(.+[^/])/?$ /cmstut/$1.php [QSA,L]

推荐答案

如果请求的 URI 路径不正确,您最好只使用一种拼写(带或不带斜杠)并重定向:

You should better use just one spelling (with or without trailing slash) and redirect if the requested URI path is incorrect:

# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]

# remove trailing slash
RewriteRule (.+)/$ /$1 [L,R=301]

这篇关于尾部斜杠给出内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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