<Directory /var/www/website/html>
Options +SymLinksIfOwnerMatch -Indexes
AllowOverride All
RewriteEngine on
# Enforce removal of trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# If the user is performing a search
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^query=([^&]+)
RewriteRule ^(.*)$ index.php?uri=$1&query=%1 [L,B]
# If the user has a token set
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^token=([^&]+)
RewriteRule ^(.*)$ index.php?uri=$1&token=%1 [L,B]
# If not existing file/directory, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [L,B]
</Directory>
将数据发布到上述QUERY_STRING
条件的服务器上的目录时,似乎RewriteRule
正在清除发布数据。
我希望修改此RewriteRule
,以便在满足这些条件时仍然可以访问帖子数据。
答案 0 :(得分:1)
这样做是为了避免在REQUEST_METHOD
为POST
时重定向:
<Directory /var/www/website/html>
Options +SymLinksIfOwnerMatch -Indexes
AllowOverride All
RewriteEngine on
# Enforce removal of trailing slash except for POST request
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301,NE]
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# If the user is performing a search
RewriteCond %{QUERY_STRING} ^query=
RewriteRule ^(.*)$ index.php?uri=$1&query=%1 [L,B,QSA]
# If the user has a token set
RewriteCond %{QUERY_STRING} ^token=
RewriteRule ^(.*)$ index.php?uri=$1&token=%1 [L,B,QSA]
# If not existing file/directory, redirect to index.php
RewriteRule ^(.*)$ index.php?uri=$1 [L,B,QSA]
</Directory>
我重构了一些规则以避免冗余条件。还可以使用QSA
标志附加以前的查询字符串。