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
Related
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]
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>
Firstly I implemented a rewrite rule for my REST API on an apache2 server with the following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ index.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ index.php [QSA,NC,L]
</IfModule>
It worked fine. If I entered e.g. http://mypage.de/REST/SomeRule/12 my index.php in the folder REST/ received the information SomeRule/12.
Now I enabled SSL on my server and I wanted to force the API to use https so I added the following code to my .htaccess file:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L]
Now I receive a page not found error. Can you see the error in the .htaccess file, or must it be somewhere else? I am not that familiar with these files. To create my API I used this tutorial.
With the help of anubhava I found the solution.
When I updated my server to run with https my folder sites-enabled included a new file sites-enabled/default-ssl. In this file I had to set
AllowOverride All
like I already did for the on using http. I addition the correct solution for the .htaccess file was the following:
<IfModule mod_rewrite.c>
RewriteEngine On
#use https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/%{REQUEST_URI} [L]
#used for api
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ index.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ index.php [QSA,NC,L]
</IfModule>
I was not able to use
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L]
because the $1 then was somehow overwritten for the next Rule.
I'm cleaning my URLs and everything looks fine but whenever I try to access any directory such as images etc then chrome shows that "This webpage has a redirect loop." However I want to protect directories inside public_html.
The .htaccess file is inside public_html
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
</ifModule>
I want to protect images, css and javascript directories but want to allow access to the admin directory.
Thank in advance.
Change order of your rules and change your trailing slash removing rule:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [R=301,L]
# block all directories except admin/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule !^admin(/|$) - [NC,F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</ifModule>
You can use this remove all code and use this one
option index allow and disallow to be index directory like
This does the trick.
Options All -Indexes
or
IndexIgnore *
for more information please check below link
http://viralpatel.net/blogs/htaccess-directory-listing-enable-disable-allow-deny-prevent-htaccess-directory-listing/
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