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

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

            // Include our default page declared above if no data is passed (no clicks on menu)


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.


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



  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥20 unity内置语言切换的按钮设置
  • ¥15 中级微观经济学,生产可能性边界问题
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?
  • ¥15 html5 qrcode 扫描器