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>
Related
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 :)
In the past, I have got this working no problems at all, but for some reason on my new server I just can't get it to work.
I have the following .htaccess file in the root of my application
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have also enabled mod_rewrite and have confirmed this with php_info()
my site is located at /var/www/html/test
Is it possible that although mod_rewrite is enabled that it is not working and if so, how can I test it?
On some server implementations, you'll need to wrap it within <IfModule> tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Also check your httpd.conf file to ensure it has:
Options FollowSymLinks
AllowOverride All
It'd also be worth checking to makesure the .htaccess file isn't being overridden by another .htaccess file.
A simple way to test if .htaccess is working
Simply put the following in your .htaccess file:
deny from All
What this does is deny access to your site from everyone. If you are presented with a 403 forbidden when trying to access the site - the .htaccess file is being included. If not - see above.
I use this on my codeigniter setup
RewriteEngine on
# prevent these directories from hitting CI
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|crossdomain\.xml)
# route everything else to the index.php
RewriteRule ^/(.*)$ /index.php/$1 [QSA]
(my setup is done in the virtualhost of .conf and not in .htaccess, though they are usually about the same configuration)
I work on PHP project using codeigniter, I remove the index.php from URL locally, here is my .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
When I upload the project online routes don't work at all, and I need to set index.php with plain url instead of the route!
for example instead of writing index I have to write
index.php/product_management_controller/index
If I write index it doesn't work even if I update the route to include index.php !! That means the routes are also not working!
my current route is
$route['index'] = "product_management_controller/index";
And here's a few things I've set in my config.php file:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
What is the solution!!
It works properly locally!!
Your server that your hosting on will need to allow .htaccess files, in your Apache config you will need to add:
AllowOverride All
to your Apache config. Then restart the Apache server.
You could also try
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
There is an documentation for removing index.php from url on codeigniter
https://ellislab.com/codeigniter/user-guide/general/urls.html
By the way you are on godaddy shared server as per the comments and you don't have access to apache config file, but the good news is you don't need to worry rewrite mode is on for you by default. :)
For some reason when I deploy my API using Restler's API Explorer (a fork of Swagger UI) to production it gives me a general 404 error when I load:
/api/explorer
When I am more explicit and state:
/api/explorer/index.html
It loads the framing for the page but then reports "404 : Not Found ../resources.json" in red text below the header:
I'm fairly certain there's something environmental flaring up as the same files locally work. I also checked the .htaccess file in the /api/explorer directory and it looks right to me:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
Any help would be appreciated.
It turns out all the problems were down to a mod_rewrite problem. I'm still not 100% on WHY this problem showed up in one environment but not others with precisely the same httpd.conf and .htaccess. Oh well, the solution is to be explicit in the rewrite rule about your base url using the RewriteBase directive.
In the API directory I now have the following .htaccess file:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
In the API-Explorer directory I now have the following .htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/explorer
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
In order to troubleshoot this problem one invaluable tip that I came across is turning on Apache's mod_rewrite logging.
# Adding logging for Rewrites
RewriteLog logs/rewrite.log
RewriteLogLevel 2
Put this in any globally scoped area of httpd.conf; I put it around the entries that were already there about logging but you can also just put it at the end if you like that better. In addition, the basics around rewrite troubleshooting includes (apologies if this basic):
make sure that your httpd.conf has AllowOverride All and Options FollowSymLinks set for the directories you serving Restler out of.
You can put all of the configuration into httpd.conf and avoid .htaccess files altogether (and it's a bit faster that way too) but if you do that remember that httpd.conf has absolute url referencing versus .htaccess's relative.
You can check the ReadMe file on the Restler Github page
https://github.com/Luracast/Restler-API-Explorer#readme
Did you add the 'Luracast\Restler\Resources' class to create resources.json at API Root?
In your own index.php, the addAPIClass section should look like this:
$r = new Restler();
$r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
// ... your own addApiClass
$r->handle();
It is in the documentation under "Use", but I had trouble figuring this out as well...
Make sure you have cache directory with write permission in your api root
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.