Codeigniter .htaccess

2020-04-16 19:43发布

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]

2条回答
走好不送
2楼-- · 2020-04-16 20:06

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

查看更多
\"骚年 ilove
3楼-- · 2020-04-16 20:31

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]
查看更多
登录 后发表回答