0

I'm using MAMP with alias named works. Codeigniter is at localhost/works/project/web

controllers doesn't work without index.php before them (localhost/works/project/web/index.php/auth/register)

$config['base_url'] = 'localhost/works/project/web/'; //with http://

$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO'; 

(I tried all of them for uri_protocol)

I created and edit .htaccess file at /User/me/works/project/web/ I tired all the .htaccess files about this issue.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Users/me/works/project/web

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#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
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
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>

creates error, which is: [error] [client ::1] File does not exist: /Users/me/works/project/web/auth

it is same when I use RewriteBase /

mod_rewrite is active in phpInfo.

I couldn't find the solution.

potan
  • 63
  • 1
  • 3
  • 13
  • https://stackoverflow.com/questions/14783666/codeigniter-htaccess-and-url-rewrite-issues/14807463#14807463 – GQ. Jul 22 '20 at 14:03
  • Below link solve my issue :) https://stackoverflow.com/questions/14783666/codeigniter-htaccess-and-url-rewrite-issues/14807463#14807463 – GQ. Jul 22 '20 at 14:05
  • Below link solved this issue :)- You can also refer it https://stackoverflow.com/questions/14783666/codeigniter-htaccess-and-url-rewrite-issues/14807463#14807463 – GQ. Jul 22 '20 at 14:06

8 Answers8

3

Your RewriteBase is wrong. It should not be the relative file path for your server, it should be the relative URL path for your rewrite rules and such. More info here.

If you've ever used HTML's <base> tag, it's pretty much the same principle. If your main localhost URL is http://localhost, and your project is in the subfolder http://localhost/my-project, then you would use RewriteBase /my-project/.

If you didn't use RewriteBase, and your project is in a subfolder, you'd have to add the subfolder to every one of your URLs and rewrites, like this:

RewriteRule ^(.*)$ /my-project/index.php/$1 [L]

Food for thought:

  • Start your .htaccess files as simple as possible. The more you throw at it right away, the more that can go wrong, and the harder it is to debug. Especially if you're a noob to .htaccess files. Don't blindly copy and paste -- figure out what things actually do.

  • The system folder access part is redundant now -- the system folder has its own .htaccess to restrict requests, just like the application folder.

Aken Roberts
  • 13,012
  • 3
  • 34
  • 40
1

1.Make below changes in application/config.php file

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2.use this in .htaccess file:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

and enable rewrite mode using below command

 a2enmod rewrite

and Edit the file /etc/apache2/sites-enabled/000-default

change the AllowOverride None to AllowOverride All.

and finally Restart your server

Rahul Chipad
  • 2,373
  • 17
  • 20
0

You certainly don't have mod_rewrite on or you did not install it with MAMP

Open your httpd config file and change

# AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

To

AllowOverride All

uncomment this line:

#LoadModule rewrite_module libexec/apache2/mod_rewrite.so 

Also make some changes to users here: /etc/apache2/users/username.conf

LoadModule php5_module        libexec/apache2/libphp5.so

DocumentRoot "/Users/username/where/ever/you/like"

<Directory "/Users/username/where/ever/you/like">
    Options Indexes MultiViews +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Get more info here http://adam.merrifield.ca/2010/08/09/apache-mod_rewrite-php-and-os-x-10-6-snow-leopard/


Restart MAMP


To find out if mod_rewrite is on, follow this answer in Stackoverflow:

How to check if mod_rewrite is enabled in php?


Just to be sure your .htaccess is not the issue, could you try this one. It's been tested:

<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteBase /Users/me/works/project/web/

    # If the start of the URL doesn't match one of these...
    RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads|css|images|js)

    # Route through index.php
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

Access to certain folders are granted above and the rewritebase has a trailing slash.


Make sure you have any other nested .htaccess overriding this very one.

Community
  • 1
  • 1
Steward Godwin Jornsen
  • 1,181
  • 1
  • 7
  • 13
  • Where are you putting the .htaccess file? which of these directories (/Users/me/works/project/web/) is your default localhost directory (I'm guess web) and which is presently holding your .htaccess? I guess web also. Your .htacess should also be in the same directory as your index.php file. Can you give me a little more details on your directory structure. – Steward Godwin Jornsen Feb 26 '13 at 19:48
  • "web" directory has these: application system userguide index.php .htacces (the one I am working with) in application directory there is one more .htaccess which includes: `Deny from all` I tried to change it too but didn't work. – potan Feb 26 '13 at 20:28
  • No don't change that one. Is web also your default MAMP folder or is a sub directory. If project is the default MAMP folder could you change rewritebase /web/. If web is, rewritebase / and then restart apache. – Steward Godwin Jornsen Feb 27 '13 at 03:46
  • Please see my edited reply. Ensure you have mod_rewrite on. It probably wasn't installed or is turned on in your current MAMP installation. Mod_rewrite is apache, you might have to make the changes I have pointed out above. That should fix things for you. – Steward Godwin Jornsen Feb 27 '13 at 05:02
  • I fixed the problem by instead of using .htacces, I write them to httpd.conf. Thanks. – potan Feb 27 '13 at 11:35
  • Ok, but are you going to mark it as answered. That would be nice. – Steward Godwin Jornsen Feb 27 '13 at 12:43
0

I fixed the problem by instead of using .htacces, I write them to httpd.conf. I checked the AllowOverride is All but I'm not sure why .htaccess isn't working. Because of I lost too much time with this issue, I'm going to use this way. Thanks for the answers.

potan
  • 63
  • 1
  • 3
  • 13
0

Use AllowOverride All on your vhost:

<Directory "/path/to/your/site">
    ....
    AllowOverride All
</Directory>
betonunes
  • 1
  • 2
0

Open your httpd config file LoadModule rewrite_module modules/mod_rewrite.so then AllowOverride All

          <Directory "C:/xampp/htdocs"> //example for xampp
               Options Indexes FollowSymLinks Includes ExecCGI
               AllowOverride All
               Order allow,deny
               Allow from all
           </Directory>
Harry S
  • 256
  • 2
  • 4
0

I have installed codeigniter in a url like the format: http://11.12.34.45/~project/

I tried different suggestions and finally this following url provided the solution:

https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

Web_Developer
  • 1,251
  • 2
  • 18
  • 34
0

You need to change two files of Apache, httpd.conf httpd-vhosts.conf

change this in httpd.conf

<Files ".ht*">
Require all denied
</Files>

to,

<Files ".ht*">
Require all granted
</Files>

and add below code in httpd-vhosts.conf,

<VirtualHost *:8000>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory  "c:/wamp64/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Allow from all
</Directory>
</VirtualHost>
Fahim Ahmed
  • 71
  • 10