After removing my codeigniter project from a xampp server to a Live server i've got an error when trying to access my home page without index.php in front..
this is my route :
$route['home'] = 'Pages/view/home';
this is my config :
$config['index_page'] = '';
$config['base_url'] = 'http://mysite/newsite';
$config['uri_protocol'] = 'REQUEST_URI';
my .htaccess file :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
so when i try to surf to www.mysite/home it gives me this error :
The requested URL /index.php/home was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
but when i surf to www.mysite/index.php/home it does work
I tried different htaccess files but without success
I am on xampp with widows 10 I use these two
RewriteEngine on
# Next two lines get rid of trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Also with your base url I would put / at the end of it
$config['base_url'] = 'http://localhost/yourproject/';
Related
i am trying to redirect sub folder installation to root
ie. http://mydomain/auth/login its actually http://mydomain/test/web/index.php/auth/login
works fine with all urls
but not working if i am trying to access http://mydomain getting 403 Forbidden error
note
http://mydomain/index.php to http://mydomain/test/web/index.php is working
http://mydomain to http://mydomain/test/web/index.php is not working
i am looking to access http://mydomain without Forbidden error and /index.php in url
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /test/web/index.php/$1 [QSA,L]
</IfModule>
First you should exclude any URI start with /test/web/index.php at your code , so t should look like this :
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !/test/web/index.php
RewriteRule ^(.*)$ /test/web/index.php/$1 [QSA,L]
</IfModule>
Then , you could handle error request that passes a rule above .
Moreover , Options -Indexes , in short ,means prevent directory listing when there is no index page at that directory , your code should look like this :
DirectoryIndex /test/web/index.php
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index [NC]
RewriteCond %{REQUEST_URI} !/test/web/index.php
RewriteRule ^ / [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !/test/web/index.php
RewriteRule ^(.*)$ /test/web/index.php/$1 [QSA,L]
</IfModule>
Note: clear browser cache then test it .
Using Htaccess, I am able to remove the www from the url but im struggling endlessly with completely removing the index.php.
I am using the codeigniter framework and I checked my config file.
$config['index_page'] = '';
$config['base_url'] = '';
Ive also tried: as someone suggested elsewhere on S.O:
$config['base_url'] = '/';
My htaccess file looked like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301]
Ive tried all the different versions of writing the mode-rewrite rule, this one works the best but it adds a question mark to the URL and a forward slash
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?/$1 [L,QSA]
The result at the moment, if i type www.mywebsite.com, it will change to mywebsite.com, which is correct.
But if I type www.mywebsite.com/someuri then it becomes www.mywebsite.com/index.php?someuri
with the last modrewrite rule the url becomes
www.mywebsite.com/?/someuri
I then tried adding the question mark after index.php like this:
# Now the CodeIgniter part
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
With the latter, if i type index.php into the URL, it doesnt go away.
I clearly dont understand mod-rewrite, can someone please guide me in the right direction.
Try the following
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
In some cases the default setting for uri_protocol does not work properly. Just replace
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
HTACCESS
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Try the following
Open config.php and do following replaces
$config['index_page'] = '';
to
$config['index_page'] = 'index.php';
config base_url
$config['base_url'] = '';
to
$ark_root = "http://".$_SERVER['HTTP_HOST'];
$ark_root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"", $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $ark_root;
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
I recently moved to godaddy Linux hosting and the .htaccess doesn't seem to work. Are there any settings which need to be done for godaddy because the .htaccess was working on local xampp server as well as hostek server.I am getting "404 Not Found" error message.i am using CodeIgniter-2.2.1 framework also i have check mod_rewrite in Loaded Modules in php.ini file was not found enable from server side .
My htaccess file located on root directory where my application is deployed.
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Please suggest.
This is work for me:
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
change your
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
to like
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
use this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
in config.php
$config['base_url'] = "";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
EDIT 01
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Working one on Godaddy shared:
RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/\?$1 [L]
<ifmodule mod_rewrite.c>
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path_to/your_website/index.php?$1 [L,QSA]
</IfModule>
I've just installed codeigniter, so if I type:
http://mysuperwebpage.comyr.com/projects/thebookshelf/index.php/welcome
It displays everythin as it should.
But I want to get rid of this index.php in the url, so you can access welcome controller without need to type index.php before /welcome:
http://mysuperwebpage.comyr.com/projects/thebookshelf/welcome
So i was following all needed steps which I found in same questions here on stack. What I've tried:
config.php:
$config['base_url'] = 'http://mysuperwebpage.comyr.com/projects/thebookshelf/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess file that is located in the root folder: http://mysuperwebpage.comyr.com/projects/thebookshelf/.htaccess
Attempt #1 (not working)
.htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Attempt #2 (not working)
.htaccess:
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Attempt #3 (not working)
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
What am i missing or doing wrong? First time using .htaccess.
Make sure you .htaccess file is under the root folder and not the application folder.
This is something you may not pay attention to.
According to CodeIgniter docs, this is one way to do it:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Well, i've found this information in the FAQ of the host:
On this page
So what i had to do is add this lines before everything:
RewriteBase /projects/thebookshelf/
So now it's looking like this:
RewriteBase /projects/thebookshelf/
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
I hope this will be helpful to people who use use virtual user home directory paths, as was in my case.
This works for me
For your .htaccess file (locate it in root folder)
RewriteEngine on
RewriteBase /yourProjectName
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
config.php
$config['base_url'] = "";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO";
Inside public_html dir open .htaccess and update below script
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
i've website built with CODEIGNITER working perfect on my local server but when i uploaded it on live it give me error 404 and after updating .htaccess with following code now its giving me 500 error
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /home/index.php?$1 [L]
any solutions...
This is an .htaccess rule so specify your RewriteBase as the manual says (you've read this of course). That's
RewriteBase /
for a DOCROOT/.htaccess and if your Codeigniter catachall script, index.php is in DOCROOT as well then the rule should be:
RewriteRule ^(.*)$ index.php/$1 [L]
this works for me
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
in config.php
$config['index_page'] = '';
and
$config['uri_protocol'] = 'AUTO';
hope it help