Can't remove index.php on CodeIgniter2.1.2 with RHEL - .htaccess

I have followed from many links to solve this problem. However, It doesn't work with my project.
Move .htaccess file to CI root directory
Config about mod_rewrite in .htaccess file (all structures that I found on the Google)
change config[‘index_page’] to an empty
Set config['uri_protocol'] = 'REQUEST_URI' or 'QUERY_STRING'
then, it shown
Not Found The requested URL /class/method was not found on this
server.
I don't know how to fixed it further. I spent so long time for this problem.

Install a fresh copy of CodeIgniter
Change $config['index_page'] to = '';
Copy this to your .htaccess
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Visit http://yourhost/codeigniter/welcome/index.
Does it work? If not, change the last line of the .htaccess above to
RewriteRule ^(.*)$ /index.php/$1 [L]
If it does not work at this point, check if your Apache supports mod_rewrite and it is enabled.

Ensure that mod_rewrite is enabled: If you're running Ubuntu open a terminal and type sudo a2enmod rewrite.
Furthermore, ensure that your .htaccess file is even being parsed. Again, on Ubuntu locate: /etc/apache2/sites-available/default and modify the <Directory> directive to:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Google search to find related Windows/Mac commands and file locations.

Related

.htaccess in /var/www/html directory not being read

I put an .htaccess file in the directory where I am hosting my site. /var/www/html
However it isnt being read.
I tried changing the AlowOverride in the httpd config file
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
And my .htaccess works on my local server, however when I try it on my hosted server it doesnt read it at all.
Here is my .htaccess file for reference.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^([0-9]+)$ index.php?week=$1
RewriteRule ^([0-9]+)/$ index.php?week=$1
Your .htaccess file could be being ignored for multiple reasons, so I would encourage you trying the following steps to determine the cause of your issue:
Can Apache read .htaccess? Check file permissions are set to something proper such as 0640 and make sure its group owner is www-data.
Is rewrite_mod enabled? Without it, RewriteEngine will not work. You can enable rewrites by running 2enmod rewrite with root permissions.
Have you restarted Apache since the last time you changed httpd.conf? In case not, restart it by running /etc/init.d/apache2 restart, again with root permissions.
If your website is still not working properly after trying these steps, check your Apache error logs. They're usually located in /var/log/apache2/error.log.
The easiest way to check if .htaccess file is loaded by apache is to add a line with wrong syntax into it. You should get 500 Internal Server Error after that if .htaccess file is being read. Remove this test line after that.
Then you may check that mod_rewrite is loaded. After that you may check that rewrite rules are working as intended with htaccess tester
Hi Can you please review if you had uncheck the below options -

Cakephp 2.x URL rewriting is not properly configured on your server

I think somehow most of us had a trouble with .htaccess I d'like to know if someone can help me.
Opensuse 12.3 :
Code:
Linux linux-hyo0.site 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux
I d'like to install Cakephp on my machine but I have an error on my webpage saying that "
Code:
URL rewriting is not properly configured on your server.
"
my /etc/sysconfig/apache2 file as this :
Code:
APACHE_MODULES="authz_host actions alias auth_basic authz_groupfile authn_file authz_user autoindex cgi dir include log_config mime negotiation setenvif status userdir asis imagemap php5 reqtimeout authz_default rewrite"
and the /etc/apache2/sysconfig.d/loadmodule.conf as this line at the end
Code:
LoadModule rewrite_module /usr/lib64/apache2/mod_rewrite.so
I did also change my file etc/apache2/defaul-server.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order Allow,Deny
Allow from all
</Directory>
Any help?
on app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and on app/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
This is quite an old question but maybe this answer is relevant for you Google users out there:
Did you change the View/Layouts/default.ctp?
This is what happens with this warning:
The warning is set in a div in View/Pages/home.ctp
In home.ctp only sets the warning when the file app/webroot/css/cake.generic.css exists
In the standard default.ctp layout, the stylesheet /css/cake.generic.css is loaded
In cake.generic.css the div with the warning is.... hidden!!!
So what happens when the default home page loads: it tries to load the cake.generic.css style sheet, which succeeds when mod_rewrite is configured correctly. So then the warning is hidden. If it fails to load the style sheet, the warning will stay visible.
This warning pops up, in short, when either there is a problem with mod_rewrite and htaccess, or you changed the layout so that the cake.generic.css is no longer loaded...
First check if you even try to load the stylesheet. Does it show up in your F12 console?
After hours trying to track down the problem I finally found that my .htaccess file never existed in the first place. I copied the following code into a new .htaccess file and hey presto.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Let me first say: I HATE CAKEPHP!!!!
I just spent hours working on this issue.
I learned that cake tests URL rewrite by checking for app/webroot/css/cake.generic.css
Make sure that exists.
My solution came after I checked the apache error_log and saw it complaining about not being able to find http:/myproject/css. Well, there is no css directory there by default. I created a link (ln -s app/webroot/css) and it solved Cake's problem.
If you got this error after new installation of Cakephp and you do not changed any of the files(css files or cake.generic.css) then do the following:
sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/sites-available/000-default.conf
Look for “DocumentRoot /var/www/html” and add the following lines directly below:
AllowOverride All
sudo service apache2 restart
Make sure you change all AllowOverride None to AllowOverride All
I have this problem and solve this copying the lines of cakebook:
http://book.cakephp.org/2.0/en/installation/url-rewriting.html
There is also a .htaccess file in the root folder, i.e. /.htaccess. This may not have been copied across as it's hidden by default by most operating systems.
Try adding this as the contents of /.htaccess and checking it makes it to the web server.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
There's more explanation at http://book.cakephp.org/2.0/en/installation/url-rewriting.html
There’s two solutions:
1) Either set the DocumentRoot in your Apache configuration file to the app/webroot/ directory, and CakePHP will use the .htaccess file there.
2) Place a .htaccess file in the root of your application, as by default I don’t think one gets created if you use the CakePHP console to generate an app. That .htaccess file should look this this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Codeigniter doesn't work without index.php

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.
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.
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
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.
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.
Use AllowOverride All on your vhost:
<Directory "/path/to/your/site">
....
AllowOverride All
</Directory>
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>
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
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>

Can we use httpd.conf instead of .htaccess for clean URL?

I have read that setting changes in httpd.conf are much better as compared to making changes in .htaccess as the later one is parsed at Runtime while .conf is parsed at the time of starting Apache. So, is it possible to have all the .htaccess functionality in httpd.conf or there are a few things that have to done in .htaccess only.
Also, can you suggest how to debug clean URL issues?
Basically, I am not able to get the clean URL working. I can access the show.php file but am not able to access the GET variables. Here is the .conf settings.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/show/([^/\.]+)/([^/\.]+) http://www.example.com/show.php?id=$1&img=$2 [L,R]
I have also added
Options Indexes MultiViews FollowSymlinks
AllowOverride All
in <Directory "/var/www/html">
Thanks.
As stated in the Apache manual on .htaccess, anything you can put in an .htaccess file can be put inside a <Directory> block within httpd.conf for better efficiency.
As for your issues with rewriting the URL, your first RewriteCond appears to only be matching URLs that aren't www.example.com (the ! in front is a negation modifier). Remove the ! and see if that fixes the issue. (You probably should remove the second RewriteCond as well, until you have the first one matching; otherwise, debugging problems will be more difficult.)

Enabling htaccess file for codeigniter

I'm trying to have htaccess work on codeigniter project but the module is not working and I don't know how to enable rewrite module. To have read the htaccess. The OS is Opensuse 12.2.
I have this directive in the default-server.conf
Alias /safememoirs/ /home/gabriele/Web/safememoirs/
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
But I don't understand
A) how to enable the module
B) Where should I put the .htaccess directive id in the default-server.conf or in the site directory?
C) This is for the localhost, what happen when I go online?
I didnt understand exactly what your question was, but here is my htaccess file for removing the index.php in the url.
it should be place in the root folder.
RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|bjs|plugins|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Resources