【问题标题】:.htaccess RewriteCond with multiple server variables.htaccess RewriteCond 与多个服务器变量
【发布时间】:2014-10-18 22:29:44
【问题描述】:

我怎样才能使用 htaccess 做类似的事情?

if (is_file($_SERVER['DOCUMENT_ROOT'].'/my_dir'.$_SERVER['REQUEST_URI']))
{
    // send file $_SERVER['DOCUMENT_ROOT'].'/my_dir'.$_SERVER['REQUEST_URI']
}
else
{
    // forward to front-end controller
}

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite web


    【解决方案1】:

    您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此代码:

    RewriteEngine On
    RewriteBase /
    
    # load /my_dir/<file> if exists
    RewriteCond %{DOCUMENT_ROOT}/my_dir/$1 -f [NC]
    RewriteRule ^(.*)$ /my_dir/$1.php [L]
    
    # otherwise use front controller
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2011-11-05
      • 2023-03-21
      相关资源
      最近更新 更多