删除双尾斜线 - 打开购物车

时间:2016-09-21 07:34:27

标签: .htaccess trailing-slash

我一直在快速升级我的htaccess文件。但是,有两个问题我似乎无法解决。我尝试了几种方法,但没有什么对我有用。

  1. 我的网站:https://www.zeroohm.com/
  2. 我的问题:

    • 当我访问zeroohm.com时,如何删除额外的尾部斜杠 目前,如果我去zeroohm.com,它会重定向到https://www.zeroohm.com//

    • 如果我访问www.zeroohm.com/robots.txt/,它会阻止我查看我的robots.txt文件(处理此指令时出错)。我怎样才能解决这个问题?这个问题发生在sitemap.xml上,它也导致了网站管理员工具的问题。   C.关于改进我的重新指导的任何想法?

  3. 我的htaccess文件

  4. 
    
    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]
    &#13;
    &#13;
    &#13;

1 个答案:

答案 0 :(得分:0)

您可以将这些规则保存在您的网站根目录.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]

在测试此更改之前清除浏览器缓存。