.htaccess apache 2.4上的重定向循环

时间:2016-03-14 07:41:16

标签: php apache .htaccess mod-rewrite

将网站移动到运行apache 2.4的新服务器后,此网站不再有效,并且出现500服务器错误。

当前.htaccess文件如下:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?name=$1 [L]

index.php文件按如下方式处理URL:

<div role="main">

         <?php
            // Defualt page will always be home.html
            $page = 'home';

            // Lets get pages based on user input 
            if (!empty($_GET['name'])) {

              //Assign a variable to a sanitised version of the data passed in the URL
              $tmp_page = basename($_GET['name']);

              //If the file exists, update $page
               if (file_exists("pages/{$tmp_page}.html")) 
                  $page = $tmp_page;

              //If the file does not exist, include our custom notfound page and don't run anymore code   
               elseif(!file_exists($tmp_page)){
                  include("pages/notfound.html");
                  exit;
              }
            }

            // Include our default page declared above if no data is passed (no clicks on menu)
            include("pages/$page.html"); 
            ?>

  </div>

我无法通过更改.htaccess来解决这个问题。我只是托管网站,所以理想情况下我不想在未经设计师同意的情况下对网站进行更改。

1 个答案:

答案 0 :(得分:1)

您的第一条规则将文件重写为文件,这就是您收到重写循环错误的原因。

尝试

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?name=$1 [L]