CodeIgniter Forums

Full Version: Check my .htaccess code please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
My goal is to add the www and enable HTTPS in all URLs, does this setup look fine?

Code:
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,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
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Maybe something like this:

Code:
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
You do not need this if your html file is setup correctly:

Code:
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)

Plus you may need to set it like this:

Code:
RewriteRule ^(.*)$ index.php?/$1 [L]
(05-01-2016, 03:58 AM)InsiteFX Wrote: [ -> ]You do not need this if your html file is setup correctly:

Code:
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)

Plus you may need to set it like this:

Code:
RewriteRule ^(.*)$ index.php?/$1 [L]

Hello,

Do you mind posting how the entire .htaccess should look if I want to add the www and enable SSL in URLs? I am not a web developer so it is hard for me to understand.

Thank you
Hi ,you can check this 
Code:
<IfModule mod_rewrite.c>

   Options +FollowSymLinks
   RewriteEngine on

   # Send request via index.php
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>
Hi everyone,

I have added an SSL certificate and would like to have www in front of my domain, please can you check my current .htaccess code and let me know if I should make some changes:

Code:
RewriteEngine On

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,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
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

Thanks!  Big Grin
Code:
Not needed and can cause errors in an .htaccess file

RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)


HTML all you need is to add this to your head section on top.

<head>
<base href="<?php echo base_url(); ?>">
</head>
I will remove that line from my current .htaccess file and add that to which file?
You do not need it at all.
Pages: 1 2