How to set up .htaccess for Kohana correctly, so that there is no ugly “index.php/” in the URL?

眉间皱痕 提交于 2019-11-30 05:18:54

问题


After 2 hours now I couldn't get it right.

The Kohana installation is accessible directly under my domain, i.e. "http://something.org/"

Instead of http://something.org/index.php/welcomde/index I want to have URLs like http://something.org/welcome/index

My .htaccess is messed up completely. It's actually the standard example.htaccess that came with the download. It's almost useless. On the kohana page is a tutorial "how to remove the index.php". It's really useless as well, since it will not even talk about how to remove it. Totally confusing.

Please, can someone provide his working .htaccess for a standard kohana installation?


回答1:


My htaccess looks like the example.

RewriteEngine On

RewriteBase /

RewriteRule ^(application|modules|system) - [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]

But you also have to change the config.php file to:

$config['index_page'] = '';



回答2:


This is our .htaccess file right now, and it seems to be working.

RewriteEngine On

# 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]

Note that we have our application, system and modules directories all outside of the web root.




回答3:


On some hosts, I think specficially when running PHP in CGI mode, you have to change

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

to

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

in your htaccess. So basically you can use the kohana recommended setup, simply replacing index.php/$1 with index.php?/$1




回答4:


Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php index.php%{REQUEST_URI} [L]



回答5:


For those who get "forbidden error" 403 on OSX with default .htaccess be sure to add as the first line in .htaccess

Options +FollowSymLinks




回答6:


Kohana 3.2 has a different convention. If you look in Kohana_URL you'll find the following function signature:

public static function site($uri = '', $protocol = NULL, $index = TRUE)

where $index is default to TRUE. By passing a $index FALSE you'll remove the index.php reference.



来源:https://stackoverflow.com/questions/966429/how-to-set-up-htaccess-for-kohana-correctly-so-that-there-is-no-ugly-index-ph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!