Problem with .htaccess and index.php - php

In my development server the, the referrer name will look like dev.host.in and the ip will look like 123.456.456.111/dev/
I am using codeigniter framework. I have already set the .htaccess file to remove the index.php. When I'm accessing site through dev.host.in/testproject/ its working fine. But when I'm accessing it with 123.456.456.111/dev/testproject/ it doesn't display the page.
But when I access 123.456.456.111/dev/testproject/index.php I am getting the site.
How to resolve this issue?

Put this in your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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>
If you're still having problems, visit this link.

Related

The requested URL /link was not found on this server. Apache & htaccess

The root page at / loads fine, but any other link gives me a The request URL was not found on this server error.
my htaccess is in the root of the application folder, and contains the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
a CodeIgniter .htaccess might look alike this... the RewriteBase is important there.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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>

Page not found in sub pages of admin panel in live server

I have hosted a website of codeigniter framework by using godaddy server.
The website is working nicely. And home page of admin panel is also working, but after first, the sub pages are giving page not found error, when I am trying to log in.
I think its a url directions error.
From Comment
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
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>
<IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule>
The below settings works for me:
First change this valiables in /application/config/config.php
$config['base_url'] = 'http://example.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Then change in .htaccess file
RewriteEngine on
Options -Indexes
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

redirecting subdomain to main domain with htaccess

I am building a website with two main sections,
so I have created two subdomains:
web1.example.com
web2.example.com
since i'm building websites with codeigniter, I want to redirect to the index.php page. here's what I did:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/web1 [R=301,NC,L]
it works as expected, but it changes the url to example.com/web1..
is there any way to keep the url web1.example.com, but still redirecting to example.com/web1?
I already am using .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
when I enter web1.example.com, the actual url to be executed should be:
example.com/web1, and file to be executed is index.php ..
Didnt tested, Modify and try this
RewriteRule ^([a-zA-Z0-9-/]+).example.com$ http://example.com/$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+).example.com/([a-zA-Z0-9-/]+) http://example.com/$1&$2 [L]
Edited 1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/index.php/%1&$1 [L,NC,QSA]

CodeIgniter 500 server error

I have a question that has had me pulling my hair over the last few weeks.. i have been having a blast developing a Codeigniter website on my local machine and everything functions as normal on the local machine, however when i upload the site to the production server then the links stop working and whenever clicked give me a 500 internal server error also ajax post requests also generate a 500 internal error from the console. I m really stumped as to what the problem could be thats why i have come to ask here, could anybody help me please. Also i don't have shell access
this is my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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>
use this as .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^app.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
assumming that index.php is your index page.
and change in config.php
$config['index_page'] = '';
if you are using sub domain set it as the RewriteBase

cannot remove index.php in CodeIgniter application

I'm deploying the web application that we made in our live server but then im having troubles in figuring out how to remove index.php.
i have read several blogs regarding how to remove index.php in codeigniter application.
i have tried this settings on my .htaccess
RewriteEngine On
RewriteBase /
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]
and on my config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
but i still can't figure out how to remove it. Do i need to edit something in the apache httpd.conf?
thanks!
Can you try removing the ? that is present after index.php in your .htaccess:
Change:
RewriteRule ^(.*)$ index.php?/$1 [L]
To:
RewriteRule ^(.*)$ /index.php/$1 [L]
This is the one I use. Tried 3 different ones before I found one that worked
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon \.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

Categories