CodeIgniter htaccess www to non www and http to https - .htaccess

I have tried many things but failed. Something work for http to https and some for www to non www. But when I try modification for both http to https along with www to non www it broke my website.
Please help me in .htaccess modification for both rules
This the full of default .htaccess file
It successfully redirects http to https and www to non-www. but when I type http://www.xzy.com page show blank
# Case 1
# -------------------------------------------------------#
# RewriteEngine On
# DirectoryIndex index.html index.php
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php/$1 [L]
# -------------------------------------------------------#
# Case 2
# -------------------------------------------------------#
# RewriteEngine on
# ExpiresActive On
# ExpiresDefault A2592000
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond $1 !^(index\.php|images|public|assets|uploads|themes|install|backups|updates|asset|mob|robots\.txt|curl.php)
# RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
# -------------------------------------------------------#
# Case 3
# -------------------------------------------------------#
# <IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteCond %{REQUEST_URI} ^system.*
# RewriteRule ^(.*)$ index.php?/$1 [L]
# RewriteCond %{REQUEST_URI} ^application.*
# RewriteRule ^(.*)$ index.php?/$1 [L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php?/$1 [L]
# </IfModule>
# -------------------------------------------------------#
# Case 4
# -------------------------------------------------------#
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# -------------------------------------------------------#
# Case 6 for SSL Hosting
# -------------------------------------------------------#
# RewriteEngine on
# ExpiresActive On
# ExpiresDefault A2592000
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond $1 !^(index\.php|images|public|assets|uploads|themes|install|updates|asset|mob|robots\.txt)
# RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
# -------------------------------------------------------#
# case 5
# -------------------------------------------------------#
#RewriteEngine On
#DirectoryIndex index.html index.php
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) index.php/$1
# -------------------------------------------------------#
# secure GIT files
RedirectMatch 404 /\.git
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
It successfully redirects http to https and www to non-www. but when I type http://www.xzy.com page show blank

Try this code to solve your issue
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php/?$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>

Related

What is better way to force user to have https and not use www?

I would like any user to have a url of https://sample.com
Conditions:
if user entered http://sample.com
if user entered http://www.sample.com
if user entered www.sample.com
if user entered sample.com
if user entered https://www.sample
Users needs to be in https://sample.com
Codes below are working but seems like there is better way to improve these.
## code from www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
## code from http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^sample\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sample\.com$
RewriteRule ^/?$ "https\:\/\/sample\.com\/" [R=301,L]
Updated:
# Cache Control Settings
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=31536000, public, must-revalidate"
</FilesMatch>
<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=31536000, must-revalidate"
</FilesMatch>
Options -Indexes
DirectoryIndex index.php
DefaultLanguage en-US
AddDefaultCharset UTF-8
ServerSignature off
SetEnv TZ Asia/Hong_Kong
SetEnv SERVER_ADMIN hello#sample.com
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|ttf|otf|eot|woff)$">
Header set Cache-Control "max-age=2419200"
</FilesMatch>
<FilesMatch "\.(js|css|pdf|swf)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<FilesMatch "\.(html|htm|txt)$">
Header set Cache-Control "max-age=600"
</FilesMatch>
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
RedirectMatch 404 ^/templates/.+\.(html|php)
RedirectMatch 404 ^/space/.+\.(html|php)
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?sample.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?twitter.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?linkedin.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [F]
RewriteCond %{HTTP_USER_AGENT} ^.*(Alexibot|Art-Online|asterias|BackDoorbot|Black.Hole|BlackWidow|BlowFish|botALot|BuiltbotTough|Bullseye|BunnySlippers|Cegbfeieh|Cheesebot|CherryPicker|ChinaClaw|CopyRightCheck|cosmos|Crescent|Custo|DISCo|DittoSpyder|DownloadsDemon|eCatch|EirGrabber|EmailCollector|EmailSiphon|EmailWolf|EroCrawler|ExpresssWebPictures|ExtractorPro|EyeNetIE|FlashGet|Foobot|FrontPage|GetRight|GetWeb!|Go-Ahead-Got-It|Go!Zilla|GrabNet|Grafula|Harvest|hloader|HMView|httplib|HTTrack|humanlinks|ImagesStripper|ImagesSucker|IndysLibrary|InfonaviRobot|InterGET|InternetsNinja|Jennybot|JetCar|JOCsWebsSpider|Kenjin.Spider|Keyword.Density|larbin|LeechFTP|Lexibot|libWeb/clsHTTP|LinkextractorPro|LinkScan/8.1a.Unix|LinkWalker|lwp-trivial|MasssDownloader|Mata.Hari|Microsoft.URL|MIDownstool|MIIxpc|Mister.PiX|MistersPiX|moget|Mozilla/3.Mozilla/2.01|Mozilla.*NEWT|Navroad|NearSite|NetAnts|NetMechanic|NetSpider|NetsVampire|NetZIP|NICErsPRO|NPbot|Octopus|Offline.Explorer|OfflinesExplorer|OfflinesNavigator|Openfind|Pagerabber|PapasFoto|pavuk|pcBrowser|ProgramsSharewares1|ProPowerbot/2.14|ProWebWalker|ProWebWalker|psbot/0.1|QueryN.Metasearch|ReGet|RepoMonkey|RMA|SiteSnagger|SlySearch|SmartDownload|Spankbot|spanner|Superbot|SuperHTTP|Surfbot|suzuran|Szukacz/1.4|tAkeOut|Teleport|TeleportsPro|Telesoft|The.Intraformant|TheNomad|TightTwatbot|Titan|toCrawl/UrlDispatcher|toCrawl/UrlDispatcher|True_Robot|turingos|Turnitinbot/1.5|URLy.Warning|VCI|VoidEYE|WebAuto|WebBandit|WebCopier|WebEMailExtrac.*|WebEnhancer|WebFetch|WebGosIS|Web.Image.Collector|WebsImagesCollector|WebLeacher|WebmasterWorldForumbot|WebReaper|WebSauger|WebsiteseXtractor|Website.Quester|WebsitesQuester|Webster.Pro|WebStripper|WebsSucker|WebWhacker|WebZip|Wget|Widow|[Ww]eb[Bb]andit|WWW-Collector-E|WWWOFFLE|XaldonsWebSpider|Xenu's|Zeus|craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures|archive.org|binlar|casper|checkpriv|choppy|clshttp|cmsworld|diavol|dotbot|feedfinder|flicky|g00g1e|heritrix|kmccrew|loader|miner|nikto|nutch|planetwork|postrank|purebot|pycurl|python|seekerspider|siclab|skygrid|sqlmap|turnit|vikspider|winhttp|xxxyy|youda|zmeu|zune).*$ [NC]
RewriteRule . - [F,L]
## DENY REQUEST BASED ON REQUEST METHOD
RewriteCond %{REQUEST_METHOD} ^(CONNECT|DEBUG|DELETE|MOVE|PUT|TRACE|TRACK|OPTIONS|HEAD)$ [NC]
RewriteRule ^.*$ - [F]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F,L]
</IfModule>
# Custom error page for error 403, 404 and 500
#ErrorDocument 404 /404_NOT_FOUND
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html
php_value post_max_size 20M
With your shown attempts, samples please try following Rules. Make sure these rules are placed at top of your htaccess file.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##NO https with/without www --> https.
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
##With/without https with www --> NO www with https.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,R=301,L]
#####All rest of your Rules coming here......
You can use a single rule for http -> https and www removal:
## code from http to https and www removal
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?sample\.com$ [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*)$ https://sample.com/$1 [NE,R=301,L]
# remove first www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# change to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^sample\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sample\.com$
RewriteRule ^/?$ "https\:\/\/sample\.com\/" [R=301,L]

how to get rid of only /home when someone visits my site?

Can some one help me here with htaccess?
Currently when someone visits my website somesite.com by default the url looks like somesite.com/home
I wish for it to only for home page to not show the /home instead show just https://www.somesite.com
here is my whole htaccess file
# Case 1
# -------------------------------------------------------#
RewriteEngine On
DirectoryIndex index.html index.php
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# -------------------------------------------------------#
# Case 2
# -------------------------------------------------------#
# RewriteEngine on
# ExpiresActive On
# ExpiresDefault A2592000
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond $1 !^(index\.php|images|public|assets|uploads|themes|install|backups|updates|asset|mob|robots\.txt|curl.php)
# RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
# -------------------------------------------------------#
# Case 3
# -------------------------------------------------------#
# <IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteCond %{REQUEST_URI} ^system.*
# RewriteRule ^(.*)$ index.php?/$1 [L]
# RewriteCond %{REQUEST_URI} ^application.*
# RewriteRule ^(.*)$ index.php?/$1 [L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php?/$1 [L]
# </IfModule>
# -------------------------------------------------------#
# Case 4
# -------------------------------------------------------#
# RewriteEngine On
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php/$1 [L]
# -------------------------------------------------------#
# Case 6 for SSL Hosting
# -------------------------------------------------------#
# RewriteEngine on
# ExpiresActive On
# ExpiresDefault A2592000
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond $1 !^(index\.php|images|public|assets|uploads|themes|install|updates|asset|mob|robots\.txt)
# RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
# -------------------------------------------------------#
# case 5
# -------------------------------------------------------#
#RewriteEngine On
#DirectoryIndex index.html index.php
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) index.php/$1
# -------------------------------------------------------#
# secure GIT files
RedirectMatch 404 /\.git
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
Could you please try following, please make sure you clear your browser cache before testing these URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^ http://%{HTTP_HOST} [R=302,L]
R=302 is temporary redirection, to make it permanent redirection use R=301 in above.
You can just add this rule at top of your .htaccess just below RewriteEngine On line:
RewriteEngine On
RewriteRule ^home/?$ / [R=301,L,NC]
# remaining rules go below this

Redirection issue in htaccess

I have one issue with my htaccess redirection code.
Suppose I request this url
https://example.com/about-us/
Then its redirect to non-slash link that means they redirect to
https://example.com/about-us
but what happens in between
https://example.com/about-us/ this url redirect to
https://example.com/about-us.html then redirect to
https://example.com/about-us
I want to remove this middle step from redirection.
I attached my htaccess code for better understanding
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTP_USER_AGENT} !Twitterbot [NC]
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
#RewriteCond %{HTTP_USER_AGENT} !Twitterbot [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} "blog"
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} "blog"
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}\.html -f
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.html [L]
</IfModule>
#Alternate default index page
DirectoryIndex index.html
## 404 Page
ErrorDocument 404 https://example.com/404
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
#ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##
# END WordPress
Thank you in advance
Keep all your redirect rules at top:
Options -MultiViews
RewriteEngine On
RewriteBase /
## remove www and turn on https in same rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_USER_AGENT} !Twitterbot [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (\S+)\.html\ HTTP [NC]
RewriteRule ^ %1 [R=301,L,NE]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/+$
RewriteRule ^ %1 [R=301,NE,L]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}.html [L]
# remaining rules go below this
Make sure to use a new browser for your testing or completely clear your browser cache.
About Options -MultiViews: Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.

Remove Double trailing slash - open cart

i have been contiously upgrading my htaccess file. however, there are 2 issues I just cant seem to fix. I have tried several approaches but nothing really worked for me.
my website: https://www.zeroohm.com/
my questions:
How can I remove the extra trailing slash when i go to zeroohm.com
currently, if i go to zeroohm.com, it redirects to https://www.zeroohm.com//
if i go to www.zeroohm.com/robots.txt/ , it stops me from viewing my robots.txt file (an error occured while processing this directive). how can i fix this? this problem happens to sitemap.xml and it is causing problems with webmaster tool too.
C. any ideas on improving my re-directs?
my htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^zeroohm\.ae$ [OR]
RewriteCond %{HTTP_HOST} ^www\.zeroohm\.ae$
RewriteRule ^/?$ "http\:\/\/www\.zeroohm\.com\/\$1\/" [R=301,L]
# check if url has www or not, add www if not available. if avaiable dont do anything.
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L]
#end
# force incoming traffic coming from HTTP to Https
RewriteCond %{HTTPS} !on$
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#end
#force trainling slash
RewriteBase /
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
#end of force trailing slash
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# cache to keep it at client pc
<ifmodule mod_expires.c>
Expiresactive on
# set default
Expiresdefault "access plus 24 hours"
Expiresbytype image/jpg "access plus 1 months"
Expiresbytype image/gif "access plus 1 months"
Expiresbytype image/jpeg "access plus 1 months"
Expiresbytype image/png "access plus 1 months"
Expiresbytype text/css "access plus 1 months"
Expiresbytype text/javascript "access plus 1 months"
Expiresbytype application/javascript "access plus 1 months"
Expiresbytype application/x-shockwave-flash "access plus 1 months"
</ifmodule>
#gzip compression
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# SEO URL Settings
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
#libwww-perl security fix
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteCond %{THE_REQUEST} \ /index\.php\?_route_=?([^&\ ]*)
RewriteRule ^ /%1? [R=301,L]
You can keep these rules in your site root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?zeroohm\.ae$ [NC]
RewriteRule ^ http://www.zeroohm.com%{REQUEST_URI} [R=301,L,NE]
# check if url has www or not, add www if not available. if avaiable don't do anything.
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
#force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
#libwww-perl security fix
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule ^ - [F,L]
RewriteCond %{THE_REQUEST} \ /index\.php\?_route_=?([^&\s]*)
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^sitemap\.xml$ index.php?route=feed/google_sitemap [L,QSA,NC]
RewriteRule ^googlebase\.xml$ index.php?route=feed/google_base [L,QSA,NC]
RewriteRule ^download/ /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule (.*) index.php?_route_=$0 [L,QSA]
Clear your browser cache before testing this change.

redirecting from non www to www

I have two websites - I have made htaccess file same for both of them (each has diffent links of course). They are same. My goal is to redirect from non www to www. Now it works for the first website. For the second one it works too but only on /index, the rest of pages doesn't redirect. Any idea what the problem might be? I believe there is no mistake in htaccess as I checked it and they should be completely the same.
Files - it works for AAA, doesn't for BBB. Htaccess code below:
AAA SITE:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]
DirectoryIndex index.html
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteEngine On
RewriteBase /
## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteEngine On
RewriteCond %{HTTP_HOST} ^aaa\.net
RewriteRule (.*) https://www.aaa.net/$1 [R=301,QSA,L]
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ErrorDocument 404 https://www.aaa.net/404page
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType text/javascript A604800
ExpiresByType application/javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType image/x-icon A604800
ExpiresByType text/html A60
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
BBB SITE:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]
DirectoryIndex index.html
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bbb\.net
RewriteRule (.*) https://www.bbb.net/$1 [R=301,QSA,L]
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ErrorDocument 404 https://www.bbb.net/404page
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType text/javascript A604800
ExpiresByType application/javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType image/x-icon A604800
ExpiresByType text/html A60
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
For both sites (AAA & BBB), use the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This translates as:
For every URI which does not start with www., rewrite the URI as:
http://www.[the-rest-of-the-domain][/the-rest-of-the-uri]

Resources