I have my website hosted at https://www.webdomain.com/
The hosted website at the above domain IS NOT CODEIGNITER
On the server, at the location my_username/public_html/www/myproject, a Codeigniter application is hosted.
Meaning, to access a controller and its function in myproject application.
I use the following URL
https://webdomain.com/myproject/controller/function
As you may have already noticed, myproject is the root folder of the Codeigniter application
I've been trying to remove myproject from the URL, but with no luck.
I've gone through several questions on stack overflow, but as I figured it out, all of those questions refer to project directories, that are not necessarily application root directory. In my case, I want to remove the name of the root directory myproject from the URL.
This is my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
Try this:
RewriteRule ^myproject/(.*)$ $1 [R]
This need to be in the root folder, I strongly recommend you go with #vivek_23 suggestion in the comment.
Have you try to set route in route.php file?
$route['controller/function'] = 'myproject/controller/function';
Try with .htaccess. I mainly used this on the localhost machine. This .htaccess file should be in the root of myproject folder. Here is the documentation for more information https://httpd.apache.org/docs/current/howto/htaccess.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Hope this will help to out :)
Related
My question is: How can i run a laravel application in a directory
(not in root) on a shared webhosting?
For some of my clients I run Laravel applications in the root folder of their selected shared webhosting and remove the /public part from the URL. To make this work i move the index.php to the root folder and change the information from the index.php to:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
Now i know that this can cause security problems but I already have found solutions to that case for shared webhosters.
The .htaccess i use to make this change is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.eot|\.woff|\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1/$2 [L,NC]
But in this case i want the laravel project to be run in a directory called test.
Folder structure:
root (public_html)
|-- test (directory with laravel project)
Now I'm not sure if i can simply change the .htaccess as i'm not very skilled with .htaccess files. What changes do i have to make, to make this work?
Note my urls:
// this link will be changed to:
www.[text-placeholder].com/test/public/css/style.css
// Output above result now:
www.[text-placeholder].com/public/css/style.css
// But should be:
www.[text-placeholder].com/test/public/css/style.css
It's easy, just place the project 1 level above the public_html folder and rename the public folder itself to public_html.
P.S. This is maybe a better way, than to use .htaccess, because now you really know fore sure the files outside of public html are out of your webroot (not accessible by hackers) and with htaccess you can make a mistake and the files are exposed.
Helllo everybody. I am desperatly trying to get codeigniter run on a webserver. The apache mod_rewrite is enabled, and I tried almost everything related i found on the internet, but nothing worked.
The directory on the webserver is
The cgi-bin folder have been already there. Posts that i have read said, the cgi-bin folder is irrelevant since it is hardly used these days.
But here is the first question: Holds this for me, too? Which .htaccess File should i use? Why is an .htaccess file put there?
None of them seems to work:
I tried several settings and I ended up with the following version for both .htaccess files:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test94252.test-account.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test94252.test-account.com/index.htm [L]
</IfModule>
My goal is simply that if i call the domain http://website.com/ that /website/application/views/index.php is called.
What is wrong with this .htaccess file?
EDIT: on my local machine i go by http://localhost/website/Controller/Function for calling that index.php file.
Please note: For the sake of testing i put a index.htm into /website/ to check whether the redirect is done, but it is not working.
I am looking forward hearing from you.
First:
No, you should safe-delete it. cgi-bin historically was the only place where executable or script code (binaries, shell scripts, etc.) could be stored. It is mostly a historic relic since most hosts allow execution of scripts from anywhere.
When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software.
.htaccess can be content password protection or image hot link prevention.
Second:
You should edit .htaccess in ./website folder.
And:
My file .htaccess run in server like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>
Updated:
Let tried again with another method.
Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Make .htaccess file in your root directory using below code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: remove <IfModule mod_rewrite.c></IfModule>
Instead of working live on my site I've decided to try and work locally and install new version later on my live site.
So I'm working with Codeigniter and have the following struture.
/htdocs/kow(site)/kowmanager(cms)
When I load https:localhost/kow it loads the correct controller however for some reason its not reconizing that kowmanager is a sub directory of kow with its own application folder and it should be loading the default controller that is set in its routes file. When I load https://localhost.com/kow/kowmanager it loads a page that says index of /kow/kowmanager and then a link to the parent directory. Which isn't anything CI related.
Inside the kow directory this is my .htaccess file. Is this the problem?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I'm using xxamp.
You need an index.php-page for each application as stated by the manual.
So I think you should copy your index.php to indexManager.php and in it change the application folder.
$application_folder = "kowmanager";
About the rewrite I am not sure but I think it is in line with:
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ indexManager.php?/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
are you using a .htaccess to remove index.php from urls ?
is /htdocs/kow the base directory of your project where CI is installed ?
you need to put kowmanagers in the controllers directory, and specify which controller to call, I'm not sure CI supports calling default controllers from directories unless you specify it in the routes.php config file.
Anyway, please give further information if you want a precise answer.
What is in kowmanager and why do you have two rewrites? If your directory structure is how I assume it is, you might get away with just removing the second kowmanager directive from your .htaccess file.
Which folder is codeigniter in? All you want to do is rewrite the url to remove index.php, but unless you're mapping the url to codeigniter's index.php, it will never be able to load controllers.
Apache has a lot of info on url rewrite. Its a lot of reading and the behavior is always pretty finicky, but maybe it will help you:
Otherwise, more info will help us help you. P.S. I'd also tag this with apache, as that is where the problem is, and you're more likely to get people who know a lot about apache to view your question.
Let's say we have the following schema:
root/
application/
-public/
index.php
css/
img/
javascript/
...
system/
...
I was thinking that if I create an .htaccess file in the root with the following rules:
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/public/index.php?url=$1 [QSA,L]
I would be able to make other folder except public unable to be accessed. Assume index.php is the file that load all the file the application need and include and require them (with relative paths obliviously): the application is actually run in index.php and every public file such as css stylesheet, images or javascript script are in the public folder. So you, as user, cannot access the system folder because if you digit www.site.com/ it refers to root/application/public/. Am I right?
But the htaccess rule I set there does not work... If I put that htaccess in the root folder and I try to access the root folder the browser shows me the list of the file of the root folder (application and system). Why isn't it working?
I used this while ago when index.php was in the root folder:
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
and it worked just fine. Why isn't the new one working?
The document root of you project should be set to the /public folder.
This way that's the only folder to web-user would have access to.
Edit: for more info check the apache manual http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
My initial code was right. Except for the third line which obliviously considered / a folder and made me see it instead of redirecting to application/public/.
Commenting the third line everything worked fine.
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/public/index.php?url=$1 [QSA,L]
I uploaded a project to a directory. I have a subdomain which points to this directory.
root/foo => foo.mydomain.com
When I go to foo.mydomain.com, I get the error "Internal Server Error", I'm sure this has to do with .htaccess, but I haven't got a clue where to go. Do I put the .htaccess in the root? or the folder which points to my subdomain.
So to Summarize:
I have a subdomain foo.mydomain.com, this points to a directory in my root (root/foo/index.php).
I need a .htaccess file which can resolve this error. My Current .htaccess file is here:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I know this .htaccess file is wrong, because it was what I used on my localhost, Where this project was in the root. Now I've taken it out the root, I need a working .htaccess to fix this. What do I need to edit in the above code to make my project work.
Project: root/foo/index.php <-- This is where my project is(directory called "foo")
I also have a subdomain pointing to ^^ The said directory.
Hey I too was having the same issue. Just now I fixed after trying a lot :D . Add RewriteBase :) .
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Hope it will work for you too.