【问题标题】:url rewriting htaccess , codeigniter only load my index pageurl 重写 htaccess ,codeigniter 只加载我的索引页面
【发布时间】:2023-03-11 09:36:01
【问题描述】:

几个小时以来我一直被这个问题困扰,如果有人可以帮助我,那就太好了,一切都在标题中,codeigniter 只加载我的索引页面,即使 url 正在改变并且我的函数被调用。我激活了 mod_rewrite 并设置了我的配置变量($config['index_page'] = ''; 和 base_url() 以及)如果有人有想法!在这里,我向您展示我的 .htaccess

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

【问题讨论】:

标签: php .htaccess codeigniter url url-rewriting


【解决方案1】:

试试这个:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

希望对你有帮助。

【讨论】:

    【解决方案2】:

    打开 config.php 并进行以下替换

    $config['index_page'] = "index.php"
    

    $config['index_page'] = ""
    

    只需替换

    $config['uri_protocol'] ="AUTO"
    

    $config['uri_protocol'] = "REQUEST_URI"
    

    也替换

    $config['base_url'] = 'localhost:8888/EHA/';
    

    $config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';
    
    $config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])) . '/';
    

    并在 HTACCESS 文件中放入以下代码

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

    【讨论】:

    • @Théo Quemar : 希望你能理解
    • 感谢您的回答我已按照您的建议做了所有操作,但它仍然无法正常工作,除了控制器的默认值外,我无法调用任何其他函数我也尝试了每个 uri_protocol,但它无法正常工作要么
    • 还有其他想法吗?
    【解决方案3】:

    你可以试试这个: 如果 .htaccess 文件没有添加。 添加这个 .htaccess 文件。

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #When your application folder isn't in the system folder
        #This snippet prevents user access to the application folder
        #Rename 'application' to your applications folder name.
        RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php?/$1 [L]
        #RewriteRule ^muser/([0-9]+) muser/index/$1
    </IfModule>
    

    config.php 并进行以下替换

    $root = "http://".$_SERVER['HTTP_HOST'];
    $root .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
    $config['base_url'] = $root;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      相关资源
      最近更新 更多