CodeIgniter Forums
Problem with base_url() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Problem with base_url() (/showthread.php?tid=73961)

Pages: 1 2 3


Problem with base_url() - TASOUNAyy - 06-29-2019

Hello guys,

I'm working on a new project, and I got a real problem ( I didn't do codeigniter/php since a long time)

I wan't to use base_url() in my view to redirect on another page, so i'm doing like this :
                            <li class="nav-main-item">
                                <a class="nav-main-link" href="<?= base_url('formulaire/inscription')?>">
                                    <span class="nav-main-link-name">Demande de compte</span>
                                </a>
                            </li>

But it's not working, it's only working if I put index.php in first.
In config.php I have:
$config['base_url'] = 'http://localhost/multi/';
$config['index_page'] = '';

I tried to change my htacces but it's not working...
Can you help me ?
Thanks


RE: Problem with base_url() - InsiteFX - 06-29-2019

You need to load the url_help, did you autoload the url_helper?


RE: Problem with base_url() - TASOUNAyy - 06-29-2019

Forgot to say but yes I autoload url & url_helper.


RE: Problem with base_url() - InsiteFX - 06-29-2019

Use CodeIgniters - anchor


RE: Problem with base_url() - anthonykusuma - 06-29-2019

could you elaborate the changes that you made in the .htaccess file?

If with index.php it's working, I believe the problem is in htacess.

You can try this rewrite code on you .htaccess.

Code:
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>



RE: Problem with base_url() - TASOUNAyy - 06-30-2019

Currently I have this htaccess:
RewriteEngine on
RewriteBase/multi/

# Add www in the start of URL if user leave
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Prevent CI index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

# Prevent user access to the CI system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# Prevent user access to the CI application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

Still not working with your htaccess.

With anchor I have this link : http://localhost/multi/formulaire/inscription. Not working.
<?= anchor('formulaire/inscription', 'Inscription', 'class="nav-main-link"') ?>


RE: Problem with base_url() - InsiteFX - 06-30-2019

You can try this one from FuelPHP has always worked for me.

Code:
<IfModule mod_rewrite.c>

    # Multiple Environment config, set this to development, testing or production
    # Set the CodeIgniter Environment.
    SetEnv CI_ENV development
    #SetEnv CI_ENV production

    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    RewriteBase /

   # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes

    # Add Font Types
    AddType application/vnd.ms-fontobject .eot
    AddType font/truetype .ttf
    AddType font/opentype .otf
    AddType font/opentype .woff
    AddType font/opentype .woff2
    AddType image/svg+xml .svg .svgz

    <FilesMatch ".(eot|ttf|otf|woff|woff2|svg|svgz)">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>

    #RewriteCond $1 !^(index\.php|resources|vendor|assets|css|js|img|images|robots\.txt)

    # Restrict your site to only one domain
    # !important USE ONLY ONE OPTION

    # Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    #RewriteCond %{HTTP_HOST} (.+)$ [NC]
    #RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

    # Remove index.php from URL
    RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
    RewriteCond %{THE_REQUEST}                ^[^/]*/index\.php [NC]
    RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

   # make HTTP Basic Authentication work on php-fcgi installs
   <IfModule mod_fcgid.c>
       RewriteCond %{HTTP:Authorization} .
       RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   </IfModule>

    # Send request via index.php if not a real file or directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # deal with php-fcgi first
    <IfModule mod_fcgid.c>
       RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>

    # no php-fcgi, check for sapi and fpm
    <IfModule !mod_fcgid.c>
        # for PHP5 sapi installations
        <IfModule mod_php5.c>
            RewriteRule ^(.*)$ index.php/$1 [QSA,L]
        </IfModule>

        <IfModule !mod_php5.c>
            # for PHP7 sapi installations
            <IfModule mod_php7.c>
                RewriteRule ^(.*)$ index.php/$1 [QSA,L]
            </IfModule>

            # for fpm installations
            <IfModule !mod_php7.c>
                RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
            </IfModule>
        </IfModule>

    </IfModule>

</IfModule>



RE: Problem with base_url() - TASOUNAyy - 07-01-2019

When I use your htaccess @InsiteFX :
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.


RE: Problem with base_url() - InsiteFX - 07-02-2019

It sounds like something is miss configured in your server.


RE: Problem with base_url() - TASOUNAyy - 07-02-2019

I use wamp, rewrite module is enable.