0

背景

我一直在为客户开发一个简单的内容管理系统,该系统允许他们为他们的移动应用程序管理新闻文章。现在系统是在本地开发服务器上编写的,运行 LAMP 和 php 版本 5。

现在我的客户正在使用他们的托管服务提供商提供的完全不同的平台(Zues Web 服务器)(我说完全不同,因为我之前对系统没有任何了解,它们可能没有太大不同,但对我来说感觉那样)在我第一次尝试将系统迁移到他们的服务器后,我遇到了一些问题,第一个是他们运行 php 版本 4 的地方,我设法说服他们升级到他们现在已经完成的 php 5。

但是我遇到的另一个问题是 Zues 处理脚本的方式,因为 Apache 有一个 .htaccess 文件可以让你做很多事情,Zues 似乎更喜欢使用单独的脚本文件来处理诸如 url 重写之类的事情。

-

问题

所以我的问题是,我不确定如何正确重写一组 .htaccess url-rewriting 规则以正确使用 Zues,遵循一些教程(很难找到适合 zues 的深入教程,或者至少它已经用于我)我有一个基本的 rewrite.script,它适用于某些页面,但不是全部。

在我的应用程序中有两个主要部分不起作用,除了 mysql 查询和表单中的一些不同元素之外,这两个部分几乎相同,所以我只讨论一个,新闻部分。

用户可以单击新闻部分,然后该部分将检查用户是否指定了他们想要查看的页码。如果他们没有,它将通过将他们重定向到为他们设置一个,/news/1/当用户查看新闻部分时,还有 2 个部分,已发布和未发布的新闻,当用户单击他们想要访问的区域时,URL 将设置为/news/publishednews/unpublished然后页面会将此值设置为会话变量并将页面重置为/news/1/

这似乎是我的问题所在,我认为它与页面的正则表达式有关,因为无论我在新闻中转到哪个页面,它都将页面 url 设置为news/1/然后 firefox 返回错误:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

所以我的主要猜测是,不是将say重定向/news/create/到页面,而是news_create.php将其重定向到news_view.php页面,但即使是这种情况,我仍然不明白为什么在apache服务器上它加载正常,而在Zues上它返回该错误。

有谁知道我做错了什么以及我需要改变什么来解决它?

-

代码

原始.htaccess

#Enable URL rewriting.
RewriteEngine on
RewriteRule ^dashboard/?$ dashboard.php [L]

RewriteRule ^account/login/?$ account_login.php [L]
RewriteRule ^account/logout/?$ account_logout.php [L]
RewriteRule ^account/settings/?$ account_settings.php [L]
RewriteRule ^account/retrieve/?$ account_retrieve.php [L]
RewriteRule ^account/retrieve/([A-Z0-9_]+)/?$ account_retrieve.php?recovery_code=$1 [L]

RewriteRule ^news/?$ news_view.php [L]
RewriteRule ^news/create/?$ news_create.php [L]
RewriteRule ^news/modify/?$ news_modify.php [L]
RewriteRule ^news/modify/([0-9]+)/?$ news_modify.php?id=$1 [L]
RewriteRule ^news/delete/([0-9]+)/?$ news_view.php?delete=$1 [L]
RewriteRule ^news/([a-z]+)/?$ news_view.php?view=$1 [L]
RewriteRule ^news/([0-9]+)/?$ news_view.php?page=$1 [L]

RewriteRule ^information/?$ information_view.php [L]
RewriteRule ^information/create/?$ information_create.php [L]
RewriteRule ^information/categories/?$ information_categories.php [L]
RewriteRule ^information/modify/?$ information_modify.php [L]
RewriteRule ^information/modify/([0-9]+)/?$ information_modify.php?id=$1 [L]
RewriteRule ^information/delete/([0-9]+)/?$ information_view.php?delete=$1 [L]
RewriteRule ^information/([a-z]+)/?$ information_view.php?view=$1 [L]
RewriteRule ^information/([0-9]+)/?$ information_view.php?page=$1 [L]

RewriteRule ^json/get/([a-z]+)/?$ json_call.php?get_article_type=$1 [L]

新的重写脚本

match URL into $ with ^/dashboard/
if matched 
    set URL=/dashboard.php
    goto END
endif





match URL into $ with ^/account/login/
if matched 
    set URL=/account_login.php
    goto END
endif

match URL into $ with ^/account/logout/
if matched 
    set URL=/account_logout.php
    goto END
endif

match URL into $ with ^/account/settings/
if matched 
    set URL=/account_settings.php
    goto END
endif

match URL into $ with ^/account/retrieve/
if matched 
    set URL=/account_retrieve.php
    goto END
endif

match URL into $ with ^/account/retrieve/([A-Z0-9_]+)/
if matched 
    set URL=/account_retrieve.php?recovery_code=$1
    goto END
endif





match URL into $ with ^/news/
if matched 
    set URL=/news_view.php
    goto END
endif

match URL into $ with ^/news/create/
if matched 
    set URL=/news_create.php
    goto END
endif

match URL into $ with ^/news/modify/
if matched 
    set URL=/news_modify.php
    goto END
endif

match URL into $ with ^/news/modify/([0-9]+)/
if matched 
    set URL=/news_modify.php?id=$1
    goto END
endif

match URL into $ with ^/news/delete/([0-9]+)/
if matched 
    set URL=/news_view.php?delete=$1
    goto END
endif

match URL into $ with ^/news/([a-z]+)/
if matched 
    set URL=/news_view.php?view=$1
    goto END
endif

match URL into $ with ^/news/([0-9]+)/
if matched 
    set URL=/news_view.php?page=$1
    goto END
endif





match URL into $ with ^/information/
if matched 
    set URL=/information_view.php
    goto END
endif

match URL into $ with ^/information/create/
if matched 
    set URL=/information_create.php
    goto END
endif

match URL into $ with ^/information/categories/
if matched 
    set URL=/information_categories.php
    goto END
endif

match URL into $ with ^/information/modify/
if matched 
    set URL=/information_modify.php
    goto END
endif

match URL into $ with ^/information/modify/([0-9]+)/
if matched 
    set URL=/information_modify.php?id=$1
    goto END
endif

match URL into $ with ^/information/delete/([0-9]+)/
if matched 
    set URL=/information_view.php?delete=$1
    goto END
endif

match URL into $ with ^/information/([a-z]+)/
if matched 
    set URL=/information_view.php?view=$1
    goto END
endif

match URL into $ with ^/information/([0-9]+)/
if matched 
    set URL=/information_view.php?page=$1
    goto END
endif





match URL into $ with ^/json/get/([a-z]+)/
if matched 
    set URL=/json_call.php?get_article_type=$1
    goto END
endif

*来自 news_view.php 的相关代码*

<?php

    //Require the configuration file.
    require('_configuration.php');

    //Establish a database connection.
    $connection->establish();

    //Check that the user is logged in.
    $account->check_login_state();

    //Check what view is selected and assign a view.
    if($_GET['view']) {
        if($_GET['view'] == 'pending') {
            $_SESSION[$G_instance_name]['view']['news'] = 'pending';
            header('location: /news/');
            die;
        } else {
            $_SESSION[$G_instance_name]['view']['news'] = 'published';
            header('location: /news/');
            die;
        }
    } else if(!isset($_SESSION[$G_instance_name]['view']['news']) or empty($_SESSION[$G_instance_name]['view']['news'])) {
        $_SESSION[$G_instance_name]['view']['news'] = 'published';
        header('location: /news/');
        die;
    }

    //Check if the modify article is still set and unset it.
    if(!empty($_SESSION[$G_instance_name]['modify']['news'])) {
        unset($_SESSION[$G_instance_name]['modify']['news']);
    }

    //Check if the user has attempted to delete an article.
    if(isset($_GET['delete'])) {
        $operation->article->delete($_GET['delete']);
    }

    //Check if the user is on a page, if note set the page to 1 as default.
    if(!isset($_GET['page']) or empty($_GET['page'])) {
        header('location: /news/1/');
        die;
    }

    //Get all news articles.
    $news_article = $operation->pagition->gather_article_data('news');

?>

任何帮助是极大的赞赏。

4

1 回答 1

0

想通了,我$在每条比赛线的末尾都错过了一个。

match URL into $ with ^/account/login/

应该是

match URL into $ with ^/account/login/$
于 2012-04-12T14:59:22.110 回答