url 重写规则后设置变量

url variable is set after rewrite rule

RewriteCond %{THE_REQUEST} \s/+blog/index\.php\?c=([^\s&]+) [NC]
RewriteRule ^ blog/%1? [R=301,L]
RewriteRule ^blog/([\w-]+)?$ blog/index.php?c= [L,QSA]

以上工作正常
现在如果没有 c 变量我需要一个规则 - 只是 index.php

RewriteCond %{THE_REQUEST} \s/+blog/index\.php [NC]
RewriteRule ^blog/ [L,R=301,NE]  

php

if(isset($_GET['c'])){$cat = $_GET['c'];}
var_dump($cat); // empty string

我不想在第二种情况下设置 c 变量
这是什么原因?

根据您显示的 samples/attempts,请尝试遵循 htaccess 规则。请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine ON
##Rules for uris which have only index.php in it.
RewriteCond %{THE_REQUEST} \s/(blog)/index\.php\s [NC]
RewriteRule ^ %1/index.php? [L,R=301,NE,NC] 

##Rules for uris which have c variable added in it.
RewriteCond %{THE_REQUEST} \s/(blog)/index\.php\?c=([^\s&]+)\s [NC]
RewriteRule ^  %1/%2? [R=301,L]

##Rules for non-existent pages.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(blog)/([\w-]+)/?$  /index.php?c= [NC,L,QSA]

OR 以上规则集会重定向到 index.php 以防没有查询字符串 URL,以防您不希望要执行重定向,请尝试遵循以下规则,确保一次仅使用上述或以下规则。

RewriteEngine ON
##Rules for uris which have only index.php in it.
RewriteCond %{THE_REQUEST} \s/(blog)/index\.php\s [NC]
RewriteRule ^ %1/index.php? [L,NC] 

##Rules for uris which have c variable added in it.    
RewriteCond %{THE_REQUEST} \s/(blog)/index\.php\?c=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]

##Rules for non-existent pages.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(blog)/([\w-]+)/?$ /index.php?c= [NC,L,QSA]