什么是重写规则^(。*)/ $?PATH = $ 1 [QSA,L]意味着我的.htaccess?我的、重写、规则、PATH

2023-09-02 11:27:23 作者:啈富、屬亍我

我需要在nginx的创建重写的工作是在我的.htaccess也有一些线,我不完全理解。

 的DirectoryIndex index.php文件

RewriteEngine叙述上
的RewriteCond%!-f
重写规则^(。*)/ $?PATH = $ 1 [QSA,L]
 

有人可以解释给我听?

解决方案

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

这条规则:

 重写规则^(。*)/ $?PATH = $ 1 [QSA,L]
 

是匹配任何URI与斜线并在内部改写为 /?路径= URI且不斜线

因此​​,对于例如:一个URI /富/ 将被改写为 / PATH = FOO QSA - 查询字符串追加 L =最后一条规则

参考: URL重写简介

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

 #请求不是一个文件
的RewriteCond%{} REQUEST_FILENAME!-f
#请求不是一个目录
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)/ $?PATH = $ 1 [QSA,L]
 
java.lang.UnsatisfiedLinkError dalvik.system.PathClassLoader...... couldn t find libweibos 问题解决办法

I need to create rewrite in nginx as is done in my .htaccess and there are some lines which I don't completely understand.

DirectoryIndex index.php

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

Can someone explain it to me?

解决方案

RewriteCond % !-f seems incorrect rule condition and is always evaluating to true.

This rule:

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

Is matching any URI with trailing slash and internally rewriting to /?path=uri-without-slash

So for ex: an URI /foo/ will be rewritten to /?path=foo

QSA - Query String Append L = Last rule

Reference: Apache mod_rewrite Introduction

UPDATE: Change that incorrect condition to:

# 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]