Unable to host codeigniter project in a web server - .htaccess

I have created a web project in codeigniter. In my localhost (windows 7) I could run the project with no errors. But when I try to host my project in my university subdomain (the administrator gave me a subdomain to host my files myproject.university.edu.bt). I uploaded all my files via filezilla. When I try to access my page, which starts with a login page. It displays the login button without any of the styles that I have coded for the site. When clicking the login button instead of displaying the next page it gives me an error The requested URL /sasec/login/user_login was not found on this server. Can anybody tell me what I should do to view/display my pages correctly! Here is my .htaccess file. The university server is running on linux
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>

Go to config/routs.php
Change this
$route['default_controller'] = '';//give your default controller name
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
in addition
Path - config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

You will have to probably change something with
RewriteBase /
in your htaccess file, link given below will give you more idea.
https://www.daniweb.com/web-development/php/threads/435526/codeigniter-remove-index-php-while-working-on-virtual-host-on-xampp
Thanks
Amit

Related

url routing throws 400 Bad Request error in CodeIgniter 4

After being helped by other users’ questions uncountable times, I finally have to ask my first question.
What I’m trying to do:
Running a CodeIgniter project (ver. 4.2.8) on a live server.
Problem:
The URL routing is not working (400 Bad Request error).
It’s a fresh installation, so there are no pages other than the default CodeIgniter homepage (the one that says “Welcome to CodeIgniter”).
The welcome page displays correctly when I access it like this:
www.example.com
www.example.com/index.php
I get the Bad Request error when I try:
www.example.com/home
Here's what I've done:
Folder structure on server:
root
|
+ | dir public_html
| |
+ | dir www.example.com //web root, this is where I put the files that were in the CI public folder
+ | dir exampleCI4 //here I put all the other CI files and folders app, vendor, writable...
I have adjusted following files:
exampleCI4/app/Config/App.php
public $baseURL = 'http://www.example.com'
www.example.com/index.php
// Load our paths config file
// This is the line that might need to be changed, depending on your folder structure.
require FCPATH . '../exampleCI4/app/Config/Paths.php';
// ^^^ Change this line if you move your application folder
At first I always got a 500 Internal Server error. After hours of searching for solutions I came across this post:
CodeIgniter4 htaccess won't work with Options All -Indexes
That indeed did solve the 500 Internal Server error, and the welcome page is displaying. I also confirmed with my hosting provider and it turns out that they don't allow Options All and FollowSymlinks.
I'm pretty sure there is something in the htaccess file that needs to be adjusted but I don't know what.
Here's the complete htaccess file:
public_html/www.example.com/.htaccess
#Disable directory browsing
Options -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
# Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ ../index.php/$1 [L,NC,QSA]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
If somebody could tell me what needs to be changed in order for it to work, that would be awesome.
Got it running.
Turned out I had forgotten to make the necessary adjustments in the spark file.
Changed this part here:
/*
*---------------------------------------------------------------
* BOOTSTRAP THE APPLICATION
*---------------------------------------------------------------
* This process sets up the path constants, loads and registers
* our autoloader, along with Composer's, loads our constants
* and fires up an environment-specific bootstrapping.
*/
// Load our paths config file
// This is the line that might need to be changed, depending on your folder structure.
require FCPATH . 'app/Config/Paths.php';
// ^^^ Change this line if you move your application folder
Can you try this in the config file? Set the base URL like:
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://". #$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;

Routing in Laravel and httpd.conf

I've set my document root as follows:
c:/wamp/www/laravel/public
When I test localhost on the browser I get the "You have arrived" page.
However when I try localhost/page0, I get a 404.
In my routes.php file I have this:
Route::get('/', function()
{
return View::make('hello');
});
Route::get('page0', function() {
return 'Test Helloworld! 0';
});
My .htaccess file looks like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It looks like everything should work. Why doesn't this work?
You might want to check if mod_rewrite is enabled by doing:
phpinfo();
You can issue this in your routes.php.
It is also possible to start a webserver in php like so from the terminal or command prompt depending on your OS:
php -S localhost:8080 -t public/
Do this from your project root. Then you can go to:
localhost:8080
And your site should be up and running. You can still use the MySQL server that is running from XAMPP or WAMPP.
Use
c:/wamp/www/laravel/public/page0
This should work.
For production and/or development you can set the document root to the "public" folder, to get rid of the "/public/" in your url:
#see https://stackoverflow.com/a/15469480/1854296 (for example)

Htaccess basic help needed

I'm trying to install friendica on my webhost (hourb, similar to 000webhost but with ssh).
I'm installing it to a directory/subdomain imoppen.domain.com (domain.com/imoppen)
But it says: Url rewrite in .htaccess is not working. Check your server configuration.
and i can't continue the installation.
I think it's something that has to do with directory's with the rewritebase part, but i don't know how to fix it.
It also gives a error in php, but that is not a very big deal for me;
Warning: set_time_limit() has been disabled for security reasons in /home/username/public_html/imoppen/boot.php on line 290
My first .htaccess (domain.com) contains:
# DO NOT REMOVE THIS LINE AND THE LINES BELOW ERRORPAGEID:yLaNyW
ErrorDocument 404 /404.html
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE yLaNyW:ERRORPAGEID
RewriteBase /
My second .htaccess (domain.com/installationdirectory) contains:
Options -Indexes
AddType application/x-java-archive .jar
AddType audio/ogg .oga
<FilesMatch "\.(out|log)$">
Deny from all
</FilesMatch>
SetEnv PHP_VER 5_3
<IfModule mod_rewrite.c>
RewriteEngine on
# Protect repository directory from browsing
RewriteRule "(^|/)\.git" - [F]
# Rewrite current-style URLs of the form 'index.php?q=x'.
# Also place auth information into REMOTE_USER for sites running
# in CGI mode.
# If you have troubles or use VirtualDocumentRoot
# uncomment this and set it to the path where your friendica installation is
# i.e.:
# Friendica url: http://some.example.com
# RewriteBase /
# Friendica url: http://some.example.com/friendica
# RewriteBase /imoppen/
#
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
</IfModule>
As you can see I've tried to use the rewritebase part, which unfortunately did not work.
My overall php version is set to 5.3
It seems like you are on hourb hosting (so am I) I solved it by going to settings -> htaccess -> Allow URL rewriting

can't remove index.php with .htaccess

i have installed codeigniter and i want to remove the index.php from url when i access localhost/aplication/index.php. i have set uncomment mod_rewrite.so from httpd.conf en this is my .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
its succes when i acces url from localhost/aplication/index.php/data/users/12 but not with this url localhost/aplication/data/users/12.
how can i fix this??
Try to follow this page about codeignitor pretty urls. Your rules look correct, but I'm terrible with regex.
Some things to look into would be checking if mod_rewrite is available by using phpinfo();. Also step three in that link talks about enabling mod_rewrite using a2enmod. And make sure you restart Apache.
check your config file there should be a line that says:
$config['index_page'] = 'index.php';
You can either set this variable to just '' or you can comment this line out completely, either way it is part of the process of removing the index.php from your codeigniter urls.
this is how you remove the index.php:
htaccess file in the root folder:
RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
for managing some static pages like: example.com/about , example.com/contact, example.com/terms etc
got to config routes file and edit:
//the controller that will be when it is exampl.com
$route['default_controller'] = 'YOUR_MAIN_CONTROLLER_NAME_HERE';
//I creted this for pages that are created dynamically or for displaying error when I want
$route['404_override'] = 'friendlyPages';

403 error when access controller in subfolder (CodeIgniter)

This is my application skeleton:
application
controllers
backend
[backend_controllers_here]
[frontend_controllers_here]
models
[shared_models_for_both_backend_and_frontend]
views
backend
[backend_views_here]
[frontend_views_here]
...
system
index.php
.htaccess
This is my .htaccess file content:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
# DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
It's nothing wrong when I type on address-bar something like these (for frontend):
mysite.local
mysite.local/index.php
mysite.local/index.php/frontend_controller
mysite.local/frontend_controller
But for backend I had a 403 error when try to access:
mysite.local/backend
mysite.local/backend/some_backend_controller
However, with index.php in URL everything is fine.
mysite.local/index.php/backend
mysite.local/index.php/backend/some_backend_controller
Am I missing something here?
Thanks for your time!
check the permission for the backend folder. it maybe prevents the webserver from reading the actual content of the directory.
The permission should allow reading for everyone
What does your config/routes.php look like? Might try something like this:
$route['backend'] = "backend/controller/method";

Resources