.htaccess not working on server - .htaccess

I have hosted a site as a sub folder like "http://www.sitename.com/projectfoldername/".
Here it shows only the home page and when clicked on any menu it shows 404 error ,so i changed the the url by writing index.php before the controller name now the url has changed from this:
"http://www.sitename.com/projectfoldername/controller-name/function-name" to this: "http://www.sitename.com/projectfoldername/index.php/controller-name/function-name" then it shows the pages but worked locally only..
my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config.php
$config['base_url'] = 'http://www.sitename.com/projectfoldername/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

If you used Apache Web Server, active your mod_rewrite
On Ubuntu:
sudo a2enmod rewrite
On Window:
Open your httpd.conf and Find the line
#LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#’

Use RewriteBase /projectfoldername in your .htaccess file like so:
RewriteEngine On
RewriteBase /projectfoldername
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]

try adding following in .htaccess, it might help you.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

#antroo ghosh , At first you have to know that which web server is using( Apache or IIS).
If you are using windows(IIS) server you can't use .htaccess, In IIS you have to use web.config instead of .htaccess.
For more details https://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig
I hope this may helps you!

Related

GoDaddy + CodeIgniter + subdomain

I'm attempting to remove index.php using the CodeIgniter framework (hosted with GoDaddy - Linux), which is currently installed to: example.com/ci
I've already declared the base_url in application/config/config.php as http://example.com/ci/.
The following is my latest test input for .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Keep in mind that the domain CI is installed under is not my hosting root. The actual path for the CI folder would be: root/mydomain/ci
After spending the better part of the day today trying a plethora of "solutions", I'm beginning to wonder if this is possible to do with GoDaddy at all, or perhaps my situation is somehow unique.
Any advice would be greatly appreciated!
EDIT: The closest I've come to fixing this issue is using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /clone/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^index.php/(.*)$ [L]
</IfModule>
.. while setting my base_url to mydomain.com/clone/ (using http:// of course) and removing index.php from index_page. Navigating to mydomain.com/clone works fine but navigating to the two pages that are part of the software results in a 404 page.
An answer to your comment, you need to add a rewrite condition to access the sites/ directory. CodeIgniter is looking for sites in the controllers folder.
RewriteCond $1 !^(index\.php|sites)
You can also add the names of your resource folders like images/video etc.
Change this
In your config.php
$config['base_url'] = '';
$config['index_page'] = '';
then in .htaccess
RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
or else you can use your .htaccess too
EDIT 01
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

codeigniter 404 page not found in intranet deployment

Please guide me what is the issue? All of my pages are showing 404 not found in intranet deployment, while main (home) page is viewing fine.
.htaccess
RewriteEngine On
RewriteBase /dna/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dna/index.php/$1 [L]
routes.php
$route['default_controller'] = "home";
$route['404_override'] = 'error/index';
$route['pages/(:any)']="pages/view/$1";
$route['contact-us'] = 'contact_us/index';
$route['news'] = 'news/index';
I'll be grateful for any help or guidance.
Codeigniter automatically gets $config['base_url'] for your site, so you can leave that blank
Make sure you have mod_rewrite enabled.
then modify your .htaccess with this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^site_hostname.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
hope that solves it.
CodeIgniter have issues with subfolders.
Create new virtual host like dna.example.com
Remove dna/ from .htaccess and base_url settings.
RewriteEngine On
RewriteBase /dna/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
The above will work assuming you have set the correct $config['base_url'] in config
$config['base_url'] = "http://localhost/DNA/" or similar depending on your set-up.

.htaccess is not working in my PHP MVC Framework

I am building my own PHP MVC framework from scratch on ubuntu. .htaccess file is not properly working in it. The folder structure and the .htaccess file content are as bellow.
Folder Structure
/MyMVCProject
/controllers
index.php
help.php
/libs
/modles
/views
.htaccess
index.php
.htaccess File content
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
When I type localh0st/MyMVCProject/help it gives me the following error.
Not Found
The requested URL /MyMVCProject/help was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localh0st Port 80
And I'm sure I have enabled mod_rewrite.
Try to do it this way and from $_REQUEST array you can get url parameter and handle it in your index.php file.
Also for testing purpose add
echo <pre>;
print_r($_REQUEST);
echo </pre>;
at first lines of index.php
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule ^(.*)$ /$1 [R=301,L]
</ifModule>
Try following RewriteRule (Copied and bit modified from Zend framework)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,NC,L]
I encountered the same thing, in my case the error was produced when I had a help.php file in the same directory. Don't know exactly why this happens...
You need to add:
RewriteBase /MyMVCProject
to your .htaccess file.

.htaccess Error in Codeigniter

I am new to Codeigniter I have put an .htaccess in root folder of codeigniter 2.1.3.
I have tried my .htaccess file on both xampp & wamp server but this is not removing my index.php.
I have also set
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
and here is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
i dont know why this is not removing my index.php page from url.
help me!!
Open config.php make sure to change $config['uri_protocol']= 'REQUEST_URI';
and in place this code in .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?/welcome/$1
That's all it works for me. Let me know if you are still facing any problem.
Check whether rewrite_module is configured as on
And try removing the condition from your code:
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|system\/plugins|robots\.txt|css\/)
RewriteRule ^(.*)$ index.php/$1 [L]
I used this code in my project it works for me,
.htaccess :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
config.php :-
$config['index_page'] = '';
$config['base_url'] = 'http://www.example.com/';
I hope this will help you
Another sily problem that could be done is that the folder that contains the application is not 755.
For be more sure about what is the problem look your apache log file , in linux /var/log/apache/error.log

Using htaccess to remove codeigniter index.php in a subdirectory

I'm trying to remove the index.php from my CI urls, but having followed the instructions it doesn't seem to be working.
I have a codeigniter installation running in a subdirectory. There is a default controller set in the routes config called main, and another controller called 'create'. The default runs fine, but going to /create returns a 324 error saying No Data Received. My htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
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>
This should be enough:
<IfModule mod_rewrite.c>
RewriteEngine On
#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 index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This is what I use. My CodeIgniter also runs in a subdir.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
.htaccess add:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Go into application/config/config.php and clear the index page config value:
// Old
$config['index_page'] = "index.php";
// New
$config['index_page'] = "";
Solved My problem hope others too... :)
Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":
sudo a2enmod rewrite
You need to restart the webserver to apply the changes:
sudo service apache2 restart
Then folow Sofia's answer.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
for ubuntu

Resources