【问题标题】:.htaccess file working on Localhost but working partially on Server.htaccess 文件在本地主机上工作,但在服务器上部分工作
【发布时间】:2021-08-07 15:56:24
【问题描述】:

所有链接都在本地主机而不是服务器上正确重定向。

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule ^css/(.*\\.css) /combine.php?type=css&files=$1
RewriteRule ^js/(.*\\.js) /combine.php?type=javascript&files=$1

ErrorDocument 404 /module/error.php 

RewriteRule ^/?app/([^/\.]+)/$ /index.php?pl=$1  [L,QSA]
RewriteRule ^/?app/([^/\.]+)$ /index.php?pl=$1  [L,QSA]

RewriteRule ^/?app/([^/\.]+)/([^/\.]+)/$ /index.php?pl=$1&type=$2  [L,QSA]
RewriteRule ^/?app/([^/\.]+)/([^/\.]+)$ /index.php?pl=$1&type=$2  [L,QSA]



RewriteRule ^/?print/([^/\.]+)/$ /index.php?pl=$1  [L,QSA]
RewriteRule ^/?print/([^/\.]+)$ /index.php?pl=$1  [L,QSA]

RewriteRule ^/?print/([^/\.]+)/([^/\.]+)/$ /index.php?pl=$1&type=$2  [L,QSA]
RewriteRule ^/?print/([^/\.]+)/([^/\.]+)$ /index.php?pl=$1&type=$2  [L,QSA]




RewriteRule ^/?report/([^/\.]+)/$ /module/report/index.php?pl=$1   [L,QSA]
RewriteRule ^/?report/([^/\.]+)$ /module/report/index.php?pl=$1   [L,QSA]



RewriteRule ^/?logout/$ /module/login/logout.php  [L,QSA]
RewriteRule ^/?logout$ /module/login/logout.php  [L,QSA]

RewriteRule ^/?login/$ /module/login/index.php?page=login  [L,QSA]
RewriteRule ^/?login$ /module/login/index.php?page=login  [L,QSA]  

RewriteRule ^/?token/$ /module/token/index.php  [L,QSA]
RewriteRule ^/?token$    /module/token/index.php  [L,QSA]


RewriteRule ^/?sql/$ /class/adminer.php  [L,QSA]
RewriteRule ^/?sql$   /class/adminer.php  [L,QSA]


RewriteRule ^/?update/$ /module/update.php  [L,QSA]
RewriteRule ^/?update$   /module/update.php  [L,QSA]


RewriteRule ^/?backup$ /module/backup/index.php  [L,QSA]
RewriteRule ^/?db_backup$   /module/backup/db_backup.php  [L,QSA]

上面的代码在本地主机上正确重定向。在服务器上,它适用于某些链接,而不适用于所有链接。例如,domain.com/app/estimate,它不起作用。对于 /app/items,它正在工作。请帮帮我...

在第一张图片中,重定向不起作用。 在第二张图片中,重定向工作正常

文件结构:

Root
|
|-->index.php
|
|-->class
|   |
|   |-->conf.php
|   |
|   |-->functions.php 
|
|-->module
|   |
|   |-->reseller
|       |
|       |-->Estimate
|       |   |
|       |   |-->estimate.php

functions.php 内容:

function value_show($text, $name, $value, $type,$count) { 
    if($type=="checked") 
    { 
        return '$(\'input[name="'.$name.'"]       
            [value="'.$value.'"]\').prop(\'checked\',true);';  
    } 
    if($type=="array") 
    { 
        return 
  
 '$(\''.$text.'[name="'.$name.'"]\').eq('.$count.').val("'.$value.'");'; 
    }   
    if($type=="multiple") 
    { 
        return '$("'.$text.'[name=\''.$name.'\']").val(['.$value.']);';   
    }   
    
    return '$(\''.$text.'[name='.$name.']\').val("'.$value.'");'; 
  }

我已经在 conf.php 中导入了functions.php,它具有在 index.php 中导入的连接字符串,如下所示

conf.php:
require("functions.php");

index.php

require("class/conf.php"); 

当我从estimate.php调用functions.php中的函数时, 它给出了加载页面。如果我删除该函数调用,那么它会显示estimate.php 的内容。

【问题讨论】:

  • 您尝试过什么解决问题的方法?你被困在哪里了? “它不工作”是什么意思?这和 PHP 有什么关系?
  • 实际上我是 php 新手。我有点困惑。它在 localhost 上重定向 url。以及为什么它在服务器上不起作用。我将此项目添加为子域。它仅显示加载程序。它不显示页面内容。

标签: php .htaccess


【解决方案1】:

如果您使用的是 XAMPP 或 MAMP

他们启用了 .htaccess 并且服务器正在积极读取该文件。 要允许 server/apache2 开始读取 .htaccess 文件,您需要告诉 apache 启用允许 .htaccess。

拿出你最喜欢的文本编辑器并转到你的 apache 配置。

在 apache config 中找到根目录。

<Directory /var/www/>
    Options Indexes FollowSymLinnks
    AllowOverride All // AllowOverride All is what tells apache to check .htaccess first
    Require all granted
<Directory>

【讨论】:

  • 您好,先生。我有域和子域。在 public html 中,我有一个 .htaccess 文件,在子域目录中,我有另一个 .htaccess 文件。对于 dmain 网站,它可以完美运行。对于子域目录,.htaccess 部分工作。如何在 Cpanel 上找到 apache 配置?
  • 我发现问题发生在哪里。请你帮助我好吗?。我有function.php。在那个文件夹之外。它的效用函数。当我从该文件调用函数时,它会在服务器上显示加载页面。但在本地主机上它工作正常。
  • @Sowmiya 我需要更多信息。你能把错误发给我吗?这可能只是一个简单的权限问题
  • 我发现了错误,先生。它是默认参数。在本地主机中它可以工作。在服务器中它会导致错误。错误是我没有设置默认参数。在函数定义中,我使用了 4 个参数。但是在函数调用中,我只使用了 2 个参数。然后我在函数定义中设置默认参数。它解决了pblm。感谢您的帮助先生。
猜你喜欢
  • 2016-02-21
  • 2017-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多