dongyan7950
2016-12-12 11:08
浏览 205
已采纳

Apache,.htaccess,多索引页面

I want to a file which executed at EVERY request, lets say index.php

RewriteRule ^(.*)$ index.php [QSA]

however, if it happens to have index2.php, lets rather execute that file. In other words, if index2.php exists, it overrides the default behaviour. So I would write this:

RewriteRule ^(.*)$ index2.php [QSA]
RewriteRule ^(.*)$ index.php [QSA]

but if index2.php doesnt exists, it fails

RewriteRule ^(.*)$ index2.php [L]
RewriteRule ^(.*)$ index.php [L]

this way too. Index2.php doesnt need to be exists, but index.php does and will always be

图片转代码服务由CSDN问答提供 功能建议

我想要一个在每个请求中执行的文件,让我们说 index.php < / p>

  RewriteRule ^(。*)$ index.php [QSA] 
   
 
 

但是,如果碰巧有 index2.php ,让我们执行该文件。 换句话说,如果 index2.php 存在,它将覆盖默认行为。 所以我写这个:

  RewriteRule ^(。*)$ index2.php [QSA] 
RewriteRule ^(。*)$ index.php [QSA] 
 <  / code>  
 
 

但如果 index2.php 不存在,则失败

  RewriteRule ^(。*  )$ index2.php [L] 
RewriteRule ^(。*)$ index.php [L] 
   
 
 

这种方式也是如此。 Index2.php 不需要存在,但 index.php 总是

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhan8581 2016-12-12 11:10
    已采纳

    You can add a condition, and apply the RewriteRule only when index2.php exists.

    RewriteCond %{DOCUMENT_ROOT}/index2.php -f
    RewriteRule ^(.*)$ index2.php [QSA,L]
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题