Codeigniter htaccess add extra slash

This is my current .htaccess:

Options +FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]

      

My config file:

$config['base_url'] = 'http://localhost/argh/';
$config['index_page'] = '';

      

And when I click, for example, on the link about us, it looks like this:

http://localhost/argh//about

      

(2 slash between argh and about)

Any suggestion?:)

EDIT:

Not sure, but it looks like a Codeigniter issue because the function:

function site_url($uri = '')
{
    if ($uri == '')
    {
        return $this->slash_item('base_url').$this->item('index_page');
    }

    if ($this->item('enable_query_strings') == FALSE)
    {
        $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
        return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
    }
    else
    {
        return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
    }
}

      

More precisely here:

return $this->slash_item('base_url').$this->item('index_page');

      

returns base_url when:

$config['index_page'] = '';

      

This is why the previous example ends like this:

http://localhost/argh//about

      

+3


source to share


4 answers


Make sure you don't write:

base_url().'/about'

      

in your requests - base_url () will use / from your config file

also remove the second one. from this line:



RewriteRule ^(.*)$ ./index.php/$1 [L]

      

:

RewriteRule ^(.*)$ /index.php/$1 [L]

      

+2


source


Use this in your .htacces file

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

      

Use this for base url

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/argh';

      



and use the path as a form action

<form method="post" action="<?php echo base_url();?>Your_Controller_Name">;

      

for href use this

<a href="<?php echo site_url("Controller_Name/Action_name"); ?>">About Us</a>

      

0


source


change this in system -> url_helper.php file

rtrim($CI->config->site_url($uri),'/');

      

0


source


Just in case someone runs into the same problem in the future:

I had the same problem due to the redirection way, for example after successful login I used even after deleting from I kept getting header("Location:".site_url()."/admin/home");

index.php

$config['index_page']=''

http://example.com//admin/home

Solution: use the function provided by CI, not i.e. redirect()

header('');

Change: for header("Location:".site_url()."/admin/home");

redirect('/admin/home')

0


source







All Articles