Welcome Guest, Not a member yet? Register   Sign In
Check my .htaccess code please
#1
Sad 

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]
Reply
#2

Maybe something like this:

Code:
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Reply
#3

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]
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(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
Reply
#5

Force SSL https:
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

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>
Reply
#7
Thumbs Up 

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
Reply
#8

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>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(This post was last modified: 09-09-2016, 09:14 AM by flaboi.)

I will remove that line from my current .htaccess file and add that to which file?
Reply
#10

You do not need it at all.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB