Codeigniter subdomain routing

前端 未结 4 704
时光取名叫无心
时光取名叫无心 2021-02-01 08:10

I\'m trying to setup a blog script on a website running on the CodeIgniter framework. I want do this without making any major code changes to my existing website\'s code. I figu

相关标签:
4条回答
  • 2021-02-01 08:41

    After 4 days of trial and error, I've finally fixed this issue!

    Turns out it was a .htaccess problem and the following rules fixed it:

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

    Thanks to everyone that read or answered this question.

    0 讨论(0)
  • 2021-02-01 08:48

    Does blog.domain.co/blog/latest also show a 404? maybe you could also take a look at the _remap() function for your default controller. http://ellislab.com/codeigniter/user-guide/general/controllers.html#default

    Basically, CodeIgniter uses the second segment of the URI to determine which function in the controller gets called. You to override this behavior through the use of the _remap() function.

    Straight from the user guide,

    If your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior in which the URI determines which function is called, allowing you to define your own function routing rules.

    public function _remap($method)
        {
            if ($method == 'some_method')
            {
                $this->$method();
            }
            else
            {
                $this->default_method();
            }
        }
    

    Hope this helps.

    0 讨论(0)
  • 2021-02-01 08:50
    $route['latest'] = "index";
    

    means that the URL http://blog.example.com/latest will look for an index() method in an index controller.

    You want

    $route['latest'] = "blog/latest"; 
    

    Codeigniter user guide has a clear explanation about routes here

    0 讨论(0)
  • 2021-02-01 09:03

    have a "AllowOverride All" in the configuration file of the subdomain in apache?

    without it "blog.notedu.mp/index.php/blog/latest" work perfectly, but "blog.notedu.mp/latest" no

    0 讨论(0)
提交回复
热议问题