Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess Codeigniter奇怪的问题,有些链接带有尾随斜杠,有些不起作用_.htaccess_Codeigniter - Fatal编程技术网

.htaccess Codeigniter奇怪的问题,有些链接带有尾随斜杠,有些不起作用

.htaccess Codeigniter奇怪的问题,有些链接带有尾随斜杠,有些不起作用,.htaccess,codeigniter,.htaccess,Codeigniter,我有个奇怪的问题。我有一个Codeigniter应用程序,它在本地机器上运行良好,但在远程服务器上却不行。以下是一些场景 有些带有尾随斜杠的链接可以正常工作,但如果没有尾随斜杠,则会在Firefox中显示“连接已重置”错误 一些没有尾部斜杠的链接可以正常工作,但是带有尾部斜杠的链接在Firefox中显示“连接被重置”错误 我确信编码没有错误,因为。我认为罪魁祸首是.htaccess文件。 下面是我的.htaccess文件 RewriteEngine on RewriteBase /demo/ R

我有个奇怪的问题。我有一个Codeigniter应用程序,它在本地机器上运行良好,但在远程服务器上却不行。以下是一些场景

  • 有些带有尾随斜杠的链接可以正常工作,但如果没有尾随斜杠,则会在Firefox中显示“连接已重置”错误

  • 一些没有尾部斜杠的链接可以正常工作,但是带有尾部斜杠的链接在Firefox中显示“连接被重置”错误

  • 我确信编码没有错误,因为。我认为罪魁祸首是.htaccess文件。 下面是我的.htaccess文件

    RewriteEngine on
    RewriteBase /demo/
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    我们将非常感谢您的帮助。谢谢

    我相信您的问题是这一行缺少一个“?”:

    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    
    将此“?”直接添加到“index.php”之后

    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    
    另外,根据我的经验,我会去掉RewriteBase上的尾随斜杠,并将其添加到$config['base_url']参数中,然后让CI为您执行此操作:

    $config['base_url'] = 'http://yourwebsite.com/demo/';
    -instead of-
    $config['base_url'] = 'http://yourwebsite.com/demo';
    
    这是我在CI中使用了一段时间的.htaccess设置,它对我很有用:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase / # TODO: add a folder name here if the application is not in web root
    
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
      # If we don't have mod_rewrite installed, all 404's
      # can be sent to index.php, and everything works as normal.
      # Submitted by: ElliotHaughin
    
      ErrorDocument 404 /index.php
    </IfModule> 
    
    
    重新启动发动机
    RewriteBase/#TODO:如果应用程序不在web根目录中,请在此处添加文件夹名称
    重写COND%{REQUEST_URI}^系统*
    重写规则^(.*)$/index.php?/$1[L]
    重写cond%{REQUEST_URI}^应用程序*
    重写规则^(.*)$/index.php?/$1[L]
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(.*)$index.php?/$1[L]
    #如果我们没有安装mod_rewrite,所有404
    #可以发送到index.php,一切正常。
    #提交人:ElliotHaughin
    ErrorDocument 404/index.php
    
    我认为您的问题是这一行缺少一个“?”:

    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    
    将此“?”直接添加到“index.php”之后

    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    
    另外,根据我的经验,我会去掉RewriteBase上的尾随斜杠,并将其添加到$config['base_url']参数中,然后让CI为您执行此操作:

    $config['base_url'] = 'http://yourwebsite.com/demo/';
    -instead of-
    $config['base_url'] = 'http://yourwebsite.com/demo';
    
    这是我在CI中使用了一段时间的.htaccess设置,它对我很有用:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase / # TODO: add a folder name here if the application is not in web root
    
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
      # If we don't have mod_rewrite installed, all 404's
      # can be sent to index.php, and everything works as normal.
      # Submitted by: ElliotHaughin
    
      ErrorDocument 404 /index.php
    </IfModule> 
    
    
    重新启动发动机
    RewriteBase/#TODO:如果应用程序不在web根目录中,请在此处添加文件夹名称
    重写COND%{REQUEST_URI}^系统*
    重写规则^(.*)$/index.php?/$1[L]
    重写cond%{REQUEST_URI}^应用程序*
    重写规则^(.*)$/index.php?/$1[L]
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则^(.*)$index.php?/$1[L]
    #如果我们没有安装mod_rewrite,所有404
    #可以发送到index.php,一切正常。
    #提交人:ElliotHaughin
    ErrorDocument 404/index.php