Jojo Coana
Jojo Coana

Reputation: 31

apache - Mod_rewrite https problems with codeigniter

I'm having trouble with my codeigniter mod_rewrite config... Here is my current config:

   RewriteCond %{SERVER_NAME} =example.com
   RewriteRule ^.* https://www.%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent,L]

   RewriteCond %{SERVER_NAME} =www.example.com
   RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent,L]

   RewriteCond %{SERVER_NAME} =www.example.com
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ https://%{SERVER_NAME}/index.php/$1 [L]

Please note, that this is not in a .htaccess file, this is in my virtual hosts file.

Accessing example.com rewrites to https://www.example.com and accessing www.example.com redirects to https://www.example.com

But accessing https://www.example.com/login brings up a 404 page...

Thanks

Upvotes: 0

Views: 77

Answers (2)

Walf
Walf

Reputation: 9308

First rule was mostly okay. Second rule was not good, don't know how you weren't getting infinite redirects from it. Third rule had a redundant condition and external redirect format but should be an internal rewrite. You don't need QSA unless your substitution contains a ?. Without a ? the query is automatically appended.

RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [R=permanent,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=permanent,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!index.php(?:$|/)).+$ index.php/$0 [END]

Upvotes: 0

santosh
santosh

Reputation: 381

Codeigniter URL is structured as follows :

Site_URL/Controller/methods

404 Page error occur in the following case :

  1. You do not have the controller
  2. Your class name does not match with controller and it's first letter is not capitalise. 3.You do not have specified method inside controller.

Upvotes: 1

Related Questions