• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whenever I enter a url which isn't the default, I get redirected to dir above root

#1
[eluser]gunnarflax[/eluser]
Ok, this is really strange for me. I'm new to codeigniter and I'm just starting to learn the framework. I recently posted a question about me not being able to include a stylesheet because of my .htaccess file (which I didn't know at the time) and now I can't access controllers by writing "controller/method" in the anchor. I need to include "index.php" before the controller and method (index.php/controller/method). Is it supposed to be like that? The strangest thing though is that when I enter a faulty URL and should be redirected to my index page I get redirected to the directory above my site root. Why is that? My .htaccess file looks like this:
Code:
<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
    #Submitted by: Fabdrol
    #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]

</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>

And my base_url is "http://localhost/admin/". But I get redirected to "http://localhost/". What am I doing wrong?

#2
[eluser]d1a8lo24[/eluser]
Ok I think I was the person that suggested the code for the .htaccess file.

Now it is true that CI out of the box uses the index.php/controller/method URL but in order to get search engine friendly URLS we need to remove the index.php and thats where the .htaccess file comes in and now we are left with www.example.com/controller/method

Now if your links still have the index.php just remove the index.php from your links and also in your configuration file correct the following.

Code:
// from
$config['index_page'] = 'index.php';
// To
$config['index_page'] = '';

If you want to use the index.php way then just remove your .htaccess file and you should be all set. If your still having problems accessing your CSS files make sure your paths are correct and don't add any .htaccess files that re write paths for now.

Code:
// If your paths to your css files look like this and you are having problems.
../../path/to/css

// Try doing this.
http://www.example.com/path/to/css

#3
[eluser]gunnarflax[/eluser]
I don't get it, it still won't work. I have the .htaccess file you provided me and it looks correct to me. I have
Code:
$config['index_page'] = '';
The redirect function is written like this:
Code:
redirect('login/form');
Why does this redirect me to the directory above root?!
Code:
$config['base_url'] = 'http://localhost/admin/';

#4
[eluser]d1a8lo24[/eluser]
Its a little hard to guess why the redirection is not working correctly since we don't know how your app its put together.

Do a simple test for debugging ass follows.

Create a testing controller in your controllers folder.

Code:
class Testing extends CI_Controller {
    
    
    function index()
    {
       redirect('testing/message');
    }

    function message()
    {
       echo 'Yes it works';
    }

Now just type in www.yourdomain.com/testing and that should route you to www.yourdomain.com/testing/message

If this works then your problem is somewhere in your code in this case you will have to provide more information on the code that you're using and if you're using any 3rd party libraries to accomplish a desire result.

If you're using your own code go over it a couple of times and see if you have any other re directions that might get trigger when an action is executed.

If worst comes to worst you might need to upload your code for someone to take a look at it and see where the problem is.

#5
[eluser]gunnarflax[/eluser]
Nope, it only works when I don't have the .htaccess file. Otherwise I get redirected to the directory above root. I'm running a xampp development environment and this only happens when I try to redirect with the .htaccess file enabled. Any ideas?

#6
[eluser]d1a8lo24[/eluser]
OK please let me know how is your CI installation setup in your local host.

Example:

/ //root of the site
/application
/system
index.php
.htaccess

and tell me just the changes that you made to your config file on CI so that I can replicate the problem.

I did see that one of your configurations that doesn't look correct but there is probably a reason why.

Code:
// Reason for the "admin"? if is just to go straight to the login you can do that through // the routes file.
$config['base_url'] = 'http://localhost/admin/';

#7
[eluser]InsiteFX[/eluser]
Sometimes you need to add this to your .htaccess file!
Code:
RewriteCond $1 !^(index\.php|css|js|img|assets|files|modules|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

Also depending on your server you may not need the ? mark.

InsiteFX

#8
[eluser]gunnarflax[/eluser]
[quote author="d1a8lo24" date="1302643872"]OK please let me know how is your CI installation setup in your local host.

Example:

/ //root of the site
/application
/system
index.php
.htaccess

and tell me just the changes that you made to your config file on CI so that I can replicate the problem.

I did see that one of your configurations that doesn't look correct but there is probably a reason why.

Code:
// Reason for the "admin"? if is just to go straight to the login you can do that through // the routes file.
$config['base_url'] = 'http://localhost/admin/';
[/quote]

The reason for the "admin" is that I have multiple projects in my localhost directory and this is the directory where I have the CodeIgniter installation and my application which I call "admin" for the time being.

This is my project hierarchy:
Code:
Localhost +-- admin (root) +--- (dir) system
                           +--- (dir) application
                           +--- (dir) style
                           +--- index.php
                           +--- .htaccess

Where in my .htaccess is this supposed to go?

Code:
RewriteCond $1 !^(index\.php|css|js|img|assets|files|modules|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

#9
[eluser]toopay[/eluser]
open your .htaccess file, and replace it ALL with this...
Code:
RewriteEngine On
RewriteBase /admin/

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 ^(.*)$ admin/index.php?/$1 [L]

#10
[eluser]toopay[/eluser]
sorry, above wrong, this...
Code:
RewriteEngine On
RewriteBase /admin/

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ admin/index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ admin/index.php?/$1 [L]

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.