【问题标题】:404 page not found while page redirection in codeigniter在 codeigniter 中进行页面重定向时找不到 404 页面
【发布时间】:2017-08-30 16:27:55
【问题描述】:

大家好,我试图重定向到管理文件夹下的仪表板控制器 addLocation 功能,我在其下方给出了显示 404 页面未找到的链接,

http://localhost/kooly/admin/dashboard/addLocation

这是我的 htaccess 文件帮助我解决这个重定向问题

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /kooly/
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</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> 

【问题讨论】:

    标签: php .htaccess codeigniter redirect


    【解决方案1】:

    试试下面的 .htaccess 代码。

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php?/$0 [PT,L]
    RewriteRule  ^/?ajax/(.*)$  ajax.php?$1 [NC,QSA,L]
    <IfModule mod_headers.c>
      header add Access-Control-Allow-Origin: "*"
    </IfModule>
    

    【讨论】:

    • 仍然找不到相同的 404 页面
    【解决方案2】:

    试试这个并保存在您的应用程序文件夹之外

    <IfModule mod_rewrite.c>
    
      RewriteEngine On
      RewriteBase /your folder/
    
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
    
      RewriteCond $1 !^(index\.php|assets|images|robots\.txt)
      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.
    
    ErrorDocument 404 /index.php
    
    </IfModule>
    

    【讨论】:

    • localhost/kooly/admin/dashboard 如果你能访问这个链接,你能试试吗?
    • 是的,我可以访问该链接。现在它对我有用,我在我的 url 中给出了大写字母我已经将 addLocation 更改为 addlocation 现在它的工作谢谢@Gennia
    【解决方案3】:

    您可以将此代码添加到您的 .htaccess 文件中

    <IfModule mod_rewrite.c>
       RewriteEngine On
    
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
    
       # Rewrite all other URLs to index.php/URL
       RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
    
    </IfModule>
    <IfModule !mod_rewrite.c>
       ErrorDocument 404 index.php
    </IfModule>
    

    使用 codeigniter 3 对我有用。

    希望对你有用!!

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 2019-12-02
      • 1970-01-01
      • 2014-06-12
      • 2021-08-09
      • 1970-01-01
      • 2015-01-14
      • 2016-11-14
      相关资源
      最近更新 更多