CodeIgniter mod_rewrite with apache 2.4 - php

I'm having trouble getting mod_rewrite to work with CodeIgniter. I'm running apache 2.4.
My web root is /Users/Jason/Development/www
This is the code I currently have in my .htaccess file located in the same directory as my main index.php file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
What am I doing wrong? I keep getting a 404 page saying the requested URL was not found on this server.

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
# exclude any paths that are not codeigniter-app related
RewriteCond %{REQUEST_URI} !^/server-status
RewriteCond %{REQUEST_URI} !^/server-info
RewriteCond %{REQUEST_URI} !^/docs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Base on sigmoid https://www.npcglib.org/~stathis/blog/2013/08/12/apache-tip-rewriting-urls-with-apache-2-4-php-fpm-mod_fastcgi_handler-codeigniter/

Related

NotFoundHttpException in RouterListener.php line 125: No route found for "GET /"

When I uploaded my php project in cpanel I get this Error. My .htaccess file has this code:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on
#uncomment next line if silex app root is in a mamp subdirectory
RewriteBase /TeraaketService
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
I'm new to php, how I can solve this problem?
Replace this in your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /*your_project_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
or,
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>

Transfer CodeIgniter project local to server, admin panel not working

I create CodeIgniter project on my local machine (Running perfectly), then I uploaded to a server with its database but I am facing the problem of not found an error while opening admin panel.
I changed config file(for base URL), database.php(for database connection).
but I don't know what to change in the .htaccess file, I took a default CodeIgniter .htaccess file but it is showing not found error.
htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /crescent_test/ad_crescent/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Try this updated code.
<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>
if this does not work then visit below link:
Page isn't working and returns HTTP error 500 in CodeIgniter
you can try this:
add htaccess file YOUR_ADMIN_FLODER root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /YOUR_ADMIN_FLODER_NAME/
Options -Indexes
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /YOUR_ADMIN_FLODER_NAME/index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /YOUR_ADMIN_FLODER_NAME/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /YOUR_ADMIN_FLODER_NAME/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /YOUR_ADMIN_FLODER_NAME/index.php
</IfModule>

404 page not found while page redirection in codeigniter

Hi all I tried to redirect to dashboard controller addLocation function under admin folder i have given the link below its showing 404 page not found,
http://localhost/kooly/admin/dashboard/addLocation
This is my htaccess file help me to solve this redirection problem
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /kooly/
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</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>
Try this and save outside of your application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your folder/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond $1 !^(index\.php|assets|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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>
Try the below .htaccess code.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
RewriteRule ^/?ajax/(.*)$ ajax.php?$1 [NC,QSA,L]
<IfModule mod_headers.c>
header add Access-Control-Allow-Origin: "*"
</IfModule>
You can add this code into your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
It's working for me using codeigniter 3.
I hope it will work for you!!

Configuring .htaccess files for CakePHP and Wordpress

I have already visited this link:
Configure .htaccess file for multiple environments
But it hasn't resolved my problem.
I am unable to access CakePHP folder from Wordpress directory. This is the .htaccess file of my root:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myer
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project/trunk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project/trunk/index.php [L]
</IfModule>
# END WordPress
This is the .htaccess file of "myer" directory:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myer
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is the .htaccess file of "myer/app" directory:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myer
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
This is the .htaccess file of "myer/app/webroot" directory:
RedirectMatch 404 /\\.svn(/|$)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myer
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
What I am getting out of these .htaccess files is "Object not found! - Error 404". What am I doing wrong?

VHost & htaccess - 500 Internal Server error

I use ISPConfig 3 to manage my domains/subdomains.
I added subdomain parim.kristian.ee which would redirect to web/parim/ (note: web/ is my document root).
ISPConfig generated such redirect to apache config:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^parim.kristian.ee [NC]
RewriteRule ^/(.*)$ /parim/$1 [L]
Now if i'll try to get static resources, such as http://parim.kristian.ee/images/1x1.gif, it serves fine, but when redirect is to codeigniter, it doesn't work.
Htaccess in web/parim/ looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
Options -Indexes
#Handle CodeIgniter request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 ./index.php
</IfModule>
NOTE: accessing the same folder via http://kristian.ee/parim/ works!
I s*ck at htaccess, so any help is appreciated.
# To remove index.php from URL
RewriteEngine On
RewriteBase /parim
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Or Simple remove RewriteBase /parim

Categories