1

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.

  1. my website: https://www.zeroohm.com/
  2. 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?

  3. 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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
m.saeed
  • 33
  • 4

1 Answers1

0

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • hey anubhava, THANKS ALOT!! it fixed .ae -> .com redirect. man, thanks. – m.saeed Sep 21 '16 at 08:15
  • but, now if u look at http://www.redirect-checker.org/index.php , you will see that there are 2 extra redirects. can you recommend a way to reduce the redirect? – m.saeed Sep 21 '16 at 08:15
  • hey, thanks a lot. butlook at the redirect-checker.org result http://zeroohm.com/arduino 301 Moved Permanently https://www.zeroohm.com/arduino 301 Moved Permanently https://www.zeroohm.com/arduino/ 200 OK – m.saeed Sep 21 '16 at 08:29
  • basically, it does a redirect from zeroohm.com/arduino to https://www.zeroohm.com/arduino and then adds the trailing slash – m.saeed Sep 21 '16 at 08:29
  • btw, thanks for the re-write of the htaccess. i really learned a couple new things. thanks! – m.saeed Sep 21 '16 at 08:31
  • Adding trailing slash rule has to be a separate one. If you enter `http://zeroohm.com/arduino/` then there is only one 301 redirect. – anubhava Sep 21 '16 at 08:44
  • 1
    aah i see. i guess then thats the best case scenario. thanks buddy, really – m.saeed Sep 21 '16 at 08:52