regex - RewriteRule ^(.*)/$ ?path=$1 [QSA,L] 在我的 .htaccess 中是什么意思?

标签 regex .htaccess mod-rewrite nginx rewrite

我需要在 nginx 中创建重写,就像在我的 .htaccess 中所做的那样,有些行我不完全理解。

DirectoryIndex index.php

RewriteEngine on
RewriteCond % !-f
RewriteRule ^(.*)/$ ?path=$1  [QSA,L]

谁能给我解释一下?

最佳答案

RewriteCond % !-f 似乎不正确的规则条件并且总是评估为真。

这条规则:

RewriteRule ^(.*)/$ ?path=$1  [QSA,L]

是否匹配任何带有斜杠的 URI 并在内部重写为 /?path=uri-without-slash

例如:URI /foo/ 将被重写为 /?path=foo

  • QSA - 查询字符串追加
  • L = 最后一条规则

引用:Apache mod_rewrite Introduction

更新:将不正确的条件更改为:

# request is not for a file
RewriteCond %{REQUEST_FILENAME} !-f
# request is not for a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ ?path=$1 [QSA,L]

关于regex - RewriteRule ^(.*)/$ ?path=$1 [QSA,L] 在我的 .htaccess 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20260571/

相关文章:

php - 从正则表达式中获取不区分大小写的单词

C# Regex 无法匹配任何内容(可能是因为无法正确转义字符)

.htaccess - 如果地址是子文件夹,htaccess 重写吗?

.htaccess - 在 htaccess 中忽略 url mod_rewrite

php - 除非首字母大写,否则 Mod_rewrite 不适用于某些规则? HTTPS服务器

javascript - 按空格分割字符串,但忽略引号中的空格

python - 网站域的正则表达式是什么用于标记化,同时将标点符号与单词分开?

.htaccess - 如何使用 .htaccess 从 URL 隐藏文件夹名称

html - .htaccess 重写/接受语言

php - 简单的模组重写