Currently, using Kohana 3.1, I can access my controllers using:
http://localhost/kohana/index.php/admin
However, I would like to access them without the "index.php" in the middle, as in:
http://localhost/kohana/admin
How can I do that? Do I need to change my .htaccess file or some config option?
I'm using the .htaccess provided with Kohana:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
Order Deny,Allow
Deny From All
# 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]
However, if you use Rewritebase /kohana/, you will still get index.php in the url.
I'm using Kohana 3, so I go to bootstrap.php and change this:
Kohana::init(array(
'base_url' => '/',
'index_file' => '',
));
Change the RewriteBase directive to where the application is. Yours would be:
# Installation directory
RewriteBase /kohana/
Also make sure you have the correct base_url in your bootstrap.
On some website I saw .htaccess suggestion:
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?kohana_uri=$0 [PT,L,QSA]
It seems that you miss kohaha folder.
It should be like this:
Kohana::init(array(
'base_url' => '/kohana/',
'index_file' => '',
));
Turn on URL rewriting by adding the following code:
In .htaccess:
RewriteEngine On
# Installation directory
RewriteBase /
In Bootstrap:
Kohana::init(array( 'base_url' => '', 'index_file' => '' ));
You need to use 'index_file' => FALSE in bootstrap.php
Source : http://kohanaframework.org/3.0/guide/kohana/tutorials/clean-urls
Related
I m trying to deploy a small project build with Yii2 (Basic Template) in a Share Hosting enviroment. Everything is working fine in local.
The Host server was like below in the root directory:
/
---logs
---index.html
After reading the doc of Yii2. I then delete the file index.html and upload my project folders into the root directory. It s now looking like this:
/
---logs
---assets
---commands
---config
---controllers
--- ...
---views
---web
--- ...
After trying the website i got a blank page. I then decided to create a htaccess file in the root of host server to point the web folder like here
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
After this i can get the index page very well with
www.example.com
and I get a blank page when i try to access for example (with url prettyUrl activated)
www.example.com/articles/list
But When I deactivate the prettyUrl, it s working like for example
www.example.com/web/index.php?r=articles/list
The .htaccess in the web folder is like this:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
# Disable Directory Browsing
Options All -Indexes
and the url rules are set in the web.php file like below:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'baseUrl' => '/',
'rules' => [
...
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
The main majority of the shared hosts disables some of the directives from the htaccess file to prevent some security issues. And if a restricted directive is found in your htaccess file you will get an 500 error page.
It's very likely that if you remove the Options +FollowSymLinks directive everything will work.
Additionally you can check out the apache error log for more information.
Assume I have a website www.mywebsite.com. My typo3 v4.7 frontend is located at, say,
www.mywebsite.com/cms/index.php
, and the backend is located at www.mywebsite.com/cms/typo3/.
How do I configure the "friendly" urls, that the realurl extension generates, in a way that urls are mapped as follows:
www.mywebsite.com/cms/index.php?id=45
to
www.mywebsite.com/cms/something
I want to use the autoconfiguration feature of realurl.
This is how the autoconfig file looks like:
<?php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']=array (
'_DEFAULT' =>
array (
'init' =>
array (
'enableCHashCache' => true,
'appendMissingSlash' => 'ifNotFile,redirect',
'adminJumpToBackend' => true,
'enableUrlDecodeCache' => true,
'enableUrlEncodeCache' => true,
'emptyUrlReturnValue' => '/cms/',
),
'pagePath' =>
array (
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'rootpage_id' => '13',
),
'fileName' =>
array (
'defaultToHTMLsuffixOnPrev' => 0,
'acceptHTMLsuffix' => 1,
'index' =>
array (
'print' =>
array (
'keyValues' =>
array (
'type' => 98,
),
),
),
),
),
);
?>
I can't get it done. There are more virtual hosts on this website. I don't want to build a new dedicated virtual host just for this typ3 installation.
Currently, redirects do not work. There is a generic with a "Page ... was not found on this server." error-message issued by Apache.
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /cms/
RewriteRule ^/cms/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)(/.*)?$ - [L]
</IfModule>
Just a tip: instead using TYPO3 in subfolder it's much more comfortable to put it into subdomain like cms.mydomain.com. In such case you don't need an additional re-configuration, and all elements works as it was normal domain.
I think your problem has currently nothing to do with RealURL and its configuration. You have a problem with mod_rewrite configuration. Start with the original one that is shipped with TYPO3 because the bit you posted is missing crucial rules. Try to set the RewriteBase but if it doesn't work, disable it.
Note that it's actually the last rule (RewriteRule .* index.php [L]) that invokes TYPO3 and makes it handle the request, which apparently doesn't happen right now.
<IfModule mod_rewrite.c>
# Enable URL rewriting
RewriteEngine On
# Change this path, if your TYPO3 installation is located in a subdirectory of the website root.
RewriteBase /cms/
# Rule for versioned static files, configured through:
# - $TYPO3_CONF_VARS['BE']['versionNumberInFilename']
# - $TYPO3_CONF_VARS['FE']['versionNumberInFilename']
# IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
# Stop rewrite processing, if we are in the typo3/ directory.
# For httpd.conf, use this line instead of the next one:
# RewriteRule ^/TYPO3root/(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
# Redirect http://example.com/typo3 to http://example.com/typo3/index_re.php and stop the rewrite processing.
# For httpd.conf, use this line instead of the next one:
# RewriteRule ^/TYPO3root/typo3$ /TYPO3root/typo3/index.php [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
# If the file/symlink/directory does not exist => Redirect to index.php.
# For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Main URL rewriting.
# For httpd.conf, use this line instead of the next one:
# RewriteRule .* /TYPO3root/index.php [L]
RewriteRule .* index.php [L]
</IfModule>
I have a yii website under a sub directory e.g
http://localhost/~username/maindirectory/yiiapp/
My htaccess file:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /yiiapp
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
protected/config/main.php
...
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
....
The issue:
let say I accesss :
step one: http://localhost/~username/maindirectory/yiiapp/
step two: click any link on home page (default yii app) let say About Us page
step three: http://localhost/~username/maindirectory/yiiapp/site/page?view=about
step four : click on any on the link (let say same page)
url will look like : http://localhost/yiiapp/site/page?view=about
so : all links are accessible as : http://localhost/yiiapp/.... , instead of removing index.php from link the while string b/w localhost and base directory is removed .
I tried this already and need the same sort of url on localhost , obviously without using sub domains
please help me fix this .
Partial answer:
The problem is that you are redirecting to an absolute URL on the same domain.
The URL probably looks like /yiiapp/site/page?view=about. However that leads to http://localhost/yiiapp/site/page?view=about. You must prepend the website directory relative to the domain (not sure if I expressed properly).
For example, the URL in the a href tag should look like /~username/maindirectory/yiiapp/site/page?view=about so you must prepend the /~username/maindirectory part from somewhere.
Have your tried:
'urlManager'=>array(
....
'baseUrl' => '/~username/maindirectory/yiiapp',
....
http://www.yiiframework.com/doc/api/1.1/CUrlManager#setBaseUrl-detail
so RewriteBase /~username/maindir/yiiapp , in .htaccess fixed the issue , not the
'baseUrl' => '/~username/maindirectory/yiiapp' thing in config/main.php
Here is the full .htaccess file:
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/maindir/yiiapp
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
===== CLARIFICATION =====
Please note this, there are hundred of answers to posts similar to this one, but people only cover a part of the problem, not the real one i'm asking here.
=====
I'm using Kohana 3.2, and i want to completely remove index.php from the url. For example, i want to access to the controller foo, action bar.
Normally, with bootstrap and htaccess correctly setted up, i can access like this:
www.domain.com/foo/bar.
But i can also access like this:
www.domain.com/index.php/foo/bar
I want to allow users to ONLY access like the first way, and not like the second way.
I have this section in bootstrap.php:
Kohana::init(array(
'base_url' => '/',
'index_file' => '',
));
i tried taking off index_file line, changing its value to FALSE, and i am still able to access foo/bar both ways.
I think the solution is modifying htaccess, but i tried some changes and it isnt working as i want. I'm using the original htaccess which came with kohana:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /knisu/
# 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]
Any help would be appreciated :)
EDIT:
I found an answer that could make it work in another post:
# Redirect from:
# http://localhost/index.php/welcome
# to
# http://localhost/welcome
#
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^index\.php/?(.*)?$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?/$1 [L]
The thing is, the author says: "this works but the problem is with the files and dirs that exists he must put the complete path for the images, css, js, etc... I will fix later"
May be that helps to find the final solution?
I think using the original htaccess is better, but with improvements.
After the...
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
This should do the redirection of the "index.php/",
# Redirect any "index.php/user/profile/" to "/user/profile/"
RewriteRule ^index.php/(.*)$ /$0 [L,R=302]
In my experience, passing css/js through controllers slower than pure apache/nginx request.
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
What 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'
));