drbvm26000 2016-03-14 07:41
浏览 54
已采纳

.htaccess apache 2.4上的重定向循环

After moving a website to a new server running apache 2.4, this website no longer works and gives a 500 server error.

The current .htaccess file is as follows:

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

The index.php files handles the urls as follows:

<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>

I have not been able to fix this by just changing the .htaccess. I'm only hosting the website, so ideally I do not want to make changes to the website without the designer's consent.

  • 写回答

1条回答 默认 最新

  • dongyao4419 2016-03-14 07:54
    关注

    Your first rule rewrites files to files, that is why you are getting a Rewrite loop error.

    Try

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?name=$1 [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵