开发者

Remove "/index/" from URIs in Kohana 3

开发者 https://www.devze.com 2023-02-26 05:34 出处:网络
As of right now all of my controllers are mapped like this: http://example.com/index/index http://example.com/index/services

As of right now all of my controllers are mapped like this:

  • http://example.com/index/index
  • http://example.com/index/services
  • http://example.com/index/contact

Wh开发者_开发百科at I want to do is change the configuration of the URI to look like this:

  • http://example.com/index
  • http://example.com/services
  • http://example.com/contact

Here is my .htaccess file

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
        Order Deny,Allow
        Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

My bootstrap.php has the following:

Kohana::init(array(
    'base_url'   => '/',
    'index_file' => FALSE
));

How can this be achieved?


Your .htaccess code looks fine. Check that your Apache configuration is fine: Kohana URL rewriting

Also, you need to edit your application/bootstrap.php and setup the initialization variables there.

Kohana::init( array(
'base_url' => '/',
'index_file' => FALSE,
) );

You may want to check the user guide, there is a page just for this setup.

http://kohanaframework.org/3.0/guide/kohana/tutorials/clean-urls


I assume that you use action_index, action_services and action_contact inside Controller_Index.

If so, all you need to do is remove the controller section from routes (in your bootstrap.php)

Route::set('posttype', '<param>', array('action' => 'index|services|contact'))
  ->defaults(array(
  'controller'=> 'index',
  'action' => 'index'
  )); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号