简体   繁体   English

结合多个htaccess规则

[英]combining multiple htaccess rules

i have a htaccess rule that remove .php extension: 我有一个删除.php扩展名的htaccess规则:

 `RewriteEngine On
  ErrorDocument 403 "Page not exist"
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([^/]+)/$ $1.php
  RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
  RewriteRule (.*)$ /$1/ [R=301,L]`

the htaccess rule below redirects to stream.php file: 下面的htaccess规则重定向到stream.php文件:

`RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /core/musicbox/stream/?tag=$1 [NC,L,QSA]`

Both rule works individually, but when combined,the rule placed below does not work. 这两个规则都是单独起作用的,但是结合使用后,下面的规则不起作用。

You have the same conditions twice: 您有两次相同的条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Which means: 意思是:

  • !-f : File %{REQUEST_FILENAME} doesn't exist. !-f :文件%{REQUEST_FILENAME}不存在。
  • !-d : Directory %{REQUEST_FILENAME} doesn't exist. !-d :目录%{REQUEST_FILENAME}不存在。

If both are true and the next one (in the first set of rules) is also true: 如果两个都成立,则下一个(在第一组规则中)也成立:

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

Then the next rule will do a 301 redirect ( R=301 ) and stop processing rules ( L ). 然后,下一个规则将执行301重定向( R=301 )并停止处理规则( L )。

RewriteRule (.*)$ /$1/ [R=301,L]

Actually, maybe there's a missing ^ in there. 实际上,也许那里缺少^ It should be: 它应该是:

RewriteRule ^(.*)$ /$1/ [R=301,L]

Anyway, that means that the second set of conditions and the subsequent rule won't be reached: 无论如何,这意味着将不会达到第二组条件和后续规则:

RewriteRule ^(.*)$ /core/musicbox/stream/?tag=$1 [NC,L,QSA]

Probably you don't need those first R=301 and L flag. 可能不需要第一个R=301L标志。 I think this is how it should look like: 我认为这应该是这样的:

RewriteEngine On
ErrorDocument 403 "Page not exist"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ /$1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /core/musicbox/stream/?tag=$1 [NC,L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM