Codeigniter .htaccess
Asked Answered
A

2

2

Sorry for my bad english...

I have the most basic possible CodeIgniter setup and can't make it work... if i access the url http://domain.com/index.php?controllerX/method it works fine.

Now I want to be able to access http://domain.com/method

I configured on routes.php "controllerX" to be the default controller and try to use the follow .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

I have tried multiple .htaccess and everytime the server just returns 403 errors. Even if my .htaccess contains only the first line "RewriteEngine on", it shows 403 errors. I have tried to set every folder to chmod 777 or 755 to test and this change nothing.

Is there a way to see what resource are giving the 403 error? Or am I comiting a mistake elsewhere?

Ok, i readed somewhere that I need "Options +FollowSymLink" on my htaccess ... with that the server show me 500 errors :(

EDIT Ok, now its working, with the follow htaccess:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
Acolyte answered 2/4, 2011 at 17:20 Comment(2)
The option is called +FollowSymLinks (with letter 's' at the end).Thilde
you should leave out the last rewrite cond (next to last line) it is no longer needed with the 2 before it. And for security you should use the SymLinksIfOwnerMatch instead of FollowSymLinks, it is much more secure. also your [L] will work better with [L,QSA] just my 2 cents thoughBioscopy
S
0

change your .htaccess file as:

apart from the changes we did in .htaccess file we also have to verify/changed the following setting :

Apache to read .htaccess files located under the /var/www/html directory. You can do this by editing httpd.conf file:

sudo nano /etc/httpd/conf/httpd.conf

Find the section and change AllowOverride None to

AllowOverride All

 <Directory /var/www/html>
    AllowOverride All
 </Directory>
Save and exit.

Now restart Apache to put the change into effect:

sudo systemctl restart httpd

rest this worked for me

Saintpierre answered 21/2, 2018 at 11:49 Comment(0)
T
-1

I think your question is also answered here

RewriteEngine On
RewriteBase /

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301]


RewriteBase /    
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]
# 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
RewriteRule ^(.*)$ index.php/$1 [L]
Tritheism answered 12/10, 2012 at 10:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.