How can I achieve all of this using htaccess. Thus far I have--
RewriteEngine On
To remove index.php
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [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
To enforce SSL and non www to www
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTP_HOST} !^(www|abc|cde|efe) [NC] #Subdomain abc and cde
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
know why its happening but can't figure out a rule to combine everything I need and make it work.
need force to https and remove index.php and non-www to www. Answers will appreciated and thanks in advance
htaccess file in CodeIgniter. htaccess is the shortened used for Hypertext Access, which is a powerful configuration file that controls the directory “. htaccess”. It is used by Apache based web servers to control various server features.
Option #1: Use the robots meta-tag with NOINDEX If the page already has the robots meta-element with the value INDEX, you can simply replace it with NOINDEX. Done. Now you just have to wait until the desired URL is removed from the Google index.
update your code with below and have a read the comments too
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
Have your rules in this order with a fix for http->https + www
rule. Finally cut down redundant rules:
DirectoryIndex index.php
RewriteEngine On
# To enforce SSL and non www to www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^(www|abc|cde|efe)\. [NC]
RewriteRule ^ https://www.example.com/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With