CodeIgniter remove index.php from href - apache

In a CodeIgniter App
this link works
link
while this one doesn't
link
What's wrong with configuration? What has to be changed in order links work without "index.php/" at the beginning?
This is done without success:
1) added to application/routes.php
$route['(:any)'] = 'controller';
2) added to application/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
3) uncommented in etc/apache2/httpd.conf
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

First of all you should blank the
$config['index_page'] = '';
in config
config.php
Then write the following code in .htaccess placed in your project's main directory.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

Use this in your .htaccess to remove the index.php from the url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
Your link should be
link
Config.php should be
$config['index_page'] = '';
The rewrite_module should be activated in apache

Related

Codeigniter Controller and methods not working without index.php

Tried all the possible solutions listed on Stackoverflow - but didn't work. Would love some help here.
Have an application that runs as follows:
localhost/bdl
Have Made the Default controller as 'Measurements'
Now I am making a call to a method within the Measurements controller called measurement_add and I get a 404 .
If I call it using localhost/bdl/index.php/measurements/measurement_add - it works - but not otherwise.
My .htaccess file is as follows:
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ /bdl/index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ /bdl/index.php/$1 [L]
My httpd.conf file is :
AllowOverride All
and uncommented the:
LoadModule rewrite_module modules/mod_rewrite.so
Can't figure it out. Any help would be appreciated.
Thanks
please use this below code in your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
ErrorDocument 404 index.php
and use below code in your config file
$config['index_page'] =''
first check mod_rewrite is enabled in your apache using phpinfo() function.
Inside your httpd.conf do below change
Options FollowSymLinks
AllowOverride All
Allow from all
In your config.php file set
$config['index_page'] =''
add below code in .htaccess at the root of your application.
RewriteEngine on
AddType application/x-shockwave-flash .swf
#RewriteBase /
RewriteCond $1 !^(index\.php|resources|MobileSiteImage|robots\.txt|flash)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Unable to remove index.php from Codeigniter 3.0 URL

I am unable to remove index.php from CodeIgnitor 3.0 URL. I have applied so many solutions but nothing worked. I am using WAMP 2.5 . rewrite_module is active in Apache . $config['index_page'] = ''. My htaccess file which is in the root folder is as follows
RewriteEngine on
RewriteBase /Reporting/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|js|img|css|captcha|robots\.txt)
RewriteRule ^(.*)$ /yourfolder/index.php/$1 [L]
Reporting is the folder in www where all the files are there.
I had problems with removing index.php with the default .htaccess code, but I managed and this is how my .htaccess looks like now.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
<Files "index.php">
AcceptPathInfo On
</Files>
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Try with this code in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
You have this in Codeigniter documentation - READ

Codeigniter mod-rewrite in apache, removing index.php

So I am quite new to codeigniter and I have been trying to get my head around removing the index.php from my local site, I have managed to make it work for the homepage after looking through other similar questions on SO but none have got it fully working. Whenever I visit another page on my site it displays the wamp page on my screen. Here is my code in codeigniter/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# !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/
RewriteBase /
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I have also put in my apache/conf/httpd.conf
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
But still no luck, is there something I've missed? Thanks in advance
Follow the following step:
1. Change the config file like this:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess vary depending on server. I some server (e.g.: Godaddy) need to use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Use this .htaccess works on most servers
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
You can uncomment the last 2 lines to force HTTPS.
Also this could also work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/
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>
Note line 3 of the 2nd .htaccess RewriteBase /foldername/ use this RewriteBase / if your script can be reached without including a folder name.

simple Apache RewriteCond and RewriteRule issue

I'm trying to follow https://github.com/crwilliams/diary-user-interface/wiki/cachebusting
If I set my HTML code to:
href="/myDir/myFile.2013103000.html"
and add to .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(html)$ $1.$3 [L]
</IfModule>
I see "Page not found" error as the browser goes to: https://www.mycompany.com/myDir/myFile.2013103000.html
Any idea what could be happening?
What can I do to trouble shoot?
Sitting at the webpage with the link, if I change .htaccess to this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+) https://www.mycompany.com/myDir/myFile.html [L]
</IfModule>
and then click the link it works (but obviously this just for troubleshooting).
UPDATE
Here's the complete .htaccess file in case something following the above can be identified as the problem:
# attempt to implement version control with cachebusting
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(html)$ $1.$3 [L]
</IfModule>
# Pruning irrelevant parts (Phil)
# force SSL and www
RewriteCond %{HTTP_HOST} ^mycompany\.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.mycompany.com/$1 [R=301,L]
# Redirect index.html to a specific subfolder;
Redirect permanent /index.html https://www.mycompany.com/home/
# enable pretty url
<IfModule mod_rewrite.c>
RewriteBase /home/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
I'd remove that last block and put it in a separate .htaccess file in your /home directory, eg
# /home/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
# not sure about the next 3 lines though
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>

What is wrong with my rewrite rule to exclude directory?

Root directory like this:
/index.php
/App
/Extend
/PHPrpc
...
I want exclude sub directory /Extend and /Phprpc from the rules.
The old .htaccess file like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
The following is modified by me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(Extend|PHPrpc) - [L] #exclude directory
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
But I get 500 Internal Server Error.
Any advise?
If you want to exclude the URLs, simply filter it using RewriteCond:
RewriteCond %{REQUEST_URI} !^/(Extend|Phprpc)/