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 关于网上一个easyx制作的见缝插针小游戏(c++)
    • ¥15 开地址法双散列函数处理碰撞
    • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
    • ¥15 联通光猫掉注册了怎么重新注册上去
    • ¥15 关于unity开发steamvr程序遇到的问题
    • ¥60 求tc downloader的下载方式
    • ¥15 华为 快捷方式 手电筒 接口
    • ¥15 Qt6.5支不支持Android13开发啊
    • ¥20 网络只能跑一半,应该如何设置
    • ¥20 Python调用百度开发者平台人脸识别接口