regex - .htaccess rule fails on server if using optional trailing slash
问题描述
I have the following set of .htaccess rules
RewriteRule ^$ /?lang=en [L,QSA]
RewriteRule ^(en|fr)/?$ /?lang=$1 [L,QSA]
RewriteRule ^(en|fr)/(.*?)/?$ /?lang=$1&page=$2 [L,QSA]
RewriteRule ^(.*?)/?$ /?lang=en&page=$1 [L,QSA]
The last rule is the newest to be implemented and is meant to be a fallback for if no language code was supplied to attempt serving the page using the default language.
The first 3 rules work perfectly in production and on local but when introducing the 4th rule it breaks. But it only breaks when the trailing slash is optional... if the trailing slash is omitted completely it is broken and if it is optional it is broken but if it is enforced it works. However this of course has the side effect of requiring a trailing slash in order for the rule to be met.
RewriteRule ^(.*?)/?$ /?lang=en&page=$1 [L,QSA] DOES NOT WORK (500 ERROR)
RewriteRule ^(.*?)$ /?lang=en&page=$1 [L,QSA] DOES NOT WORK (500 ERROR)
RewriteRule ^(.*?)/$ /?lang=en&page=$1 [L,QSA] WORKS BUT REQUIRES TRAILING SLASH
Whats going on? TIA
解决方案
推荐阅读
- json - Meteor EJSON 支持构造函数
- ios - 连接到同一wifi网络IOS上的设备
- android - Travis build 找不到包 lldb;3.1
- button - 如何在vuetify中制作具有相同宽度的不同文本长度的2个按钮?
- python - Python Regex - 从字符串末尾抓取一块空白
- windows - 我在这个批处理文件中的代码是有意义的,但它不能正常工作
- ruby - 如何在ruby中压缩包含子文件夹的文件夹
- swiftui - 悬停自定义按钮时的矩形叠加
- python - 使用python 3.6版在jetbrains pycharm中安装wordcloud失败
- c# - 将 2 个转换为 int 的数组字符串加在一起时出现我不明白的错误