令人困惑的htaccess文件 - 只需添加一个301但它不会起作用

时间:2018-03-17 12:25:26

标签: apache .htaccess redirect

我需要从1个URL添加301重定向到另一个URL。但是,我接受了一个非常令人困惑的htaccess(不是我的工作),当我在底部添加301重定向规则时,它不起作用并且htaccess打破了网站。这是htaccess文件(我用' dummyadd'掩盖了地址):

Options -Indexes


    Order Allow,Deny
    Deny from all



    RewriteEngine On

    # RewriteBase /dummyadd/public_html/

    RewriteRule ^category/30/tub-chairs-and-sofas$ http://www.dummyadd.co.uk/category/3/tub-chairs-and-sofas [R=301,L]


    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule category/(\d+)/.+ shop.php?sec=cat&cat=$1 [L,QSA]

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule product/(\d+)/.+ shop.php?sec=prod&prod=$1 [L,QSA]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^VP\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/shop\.php" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^default\.aspx$ "http\:\/\/www\.dummyadd\.co\.uk\/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^Cat\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/shop\.php" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^cat\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/shop\.php" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^outdoor\.html\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/category\/7\/outdoor\-furniture/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^chairs\.html\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/category\/1\/chairs\-and\-banquette\-seating/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^office\.html\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/category\/22\/office\-furniture/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^bar_stools\.html\/?(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/category\/5\/stools\-and\-bar\-stools/" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^category\/30\/tub\-chairs\-and\-sofas$ "http\:\/\/www\.dummyadd\.co\.uk\/category\/3\/tub\-chairs\-and\-sofas" [R=301,L]

    RewriteCond %{HTTP_HOST} ^dummyadd\.co\.uk$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.dummyadd\.co\.uk$
    RewriteRule ^(.*)$ "http\:\/\/www\.dummyadd\.co\.uk\/$1" [R=301,L]

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


    # Force compression for mangled `Accept-Encoding` request headers
    # https://developer.yahoo.com/blogs/ydn/pushing-beyond-gzipping-25601.html



            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding



    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    # Compress all output labeled with one of the following media types.
    #
    # (!) For Apache versions below version 2.3.7 you don't need to
    # enable `mod_filter` and can remove the ``
    # and `` lines as `AddOutputFilterByType` is still in
    # the core directives.
    #
    # https://httpd.apache.org/docs/current/mod/mod_filter.html#addoutputfilterbytype


        AddOutputFilterByType DEFLATE "application/atom+xml" \
                                      "application/javascript" \
                                      "application/json" \
                                      "application/ld+json" \
                                      "application/manifest+json" \
                                      "application/rdf+xml" \
                                      "application/rss+xml" \
                                      "application/schema+json" \
                                      "application/vnd.geo+json" \
                                      "application/vnd.ms-fontobject" \
                                      "application/x-font-ttf" \
                                      "application/x-javascript" \
                                      "application/x-web-app-manifest+json" \
                                      "application/xhtml+xml" \
                                      "application/xml" \
                                      "font/eot" \
                                      "font/opentype" \
                                      "image/bmp" \
                                      "image/svg+xml" \
                                      "image/vnd.microsoft.icon" \
                                      "image/x-icon" \
                                      "text/cache-manifest" \
                                      "text/css" \
                                      "text/html" \
                                      "text/javascript" \
                                      "text/plain" \
                                      "text/vcard" \
                                      "text/vnd.rim.location.xloc" \
                                      "text/vtt" \
                                      "text/x-component" \
                                      "text/x-cross-domain-policy" \
                                      "text/xml"




# ----------------------------------------------------------------------
# | Expires headers                                                    |
# ----------------------------------------------------------------------

# Serve resources with far-future expires headers.
#
# (!) If you don't control versioning with filename-based
# cache busting, you should consider lowering the cache times
# to something like one week.
#
# https://httpd.apache.org/docs/current/mod/mod_expires.html



    ExpiresActive on
    ExpiresDefault                                      "access plus 1 month"

  # CSS
    ExpiresByType text/css                              "access plus 1 year"

  # Data interchange
    ExpiresByType application/atom+xml                  "access plus 1 hour"
    ExpiresByType application/rdf+xml                   "access plus 1 hour"
    ExpiresByType application/rss+xml                   "access plus 1 hour"

    ExpiresByType application/json                      "access plus 0 seconds"
    ExpiresByType application/ld+json                   "access plus 0 seconds"
    ExpiresByType application/schema+json               "access plus 0 seconds"
    ExpiresByType application/vnd.geo+json              "access plus 0 seconds"
    ExpiresByType application/xml                       "access plus 0 seconds"
    ExpiresByType text/xml                              "access plus 0 seconds"

  # Favicon (cannot be renamed!) and cursor images
    ExpiresByType image/vnd.microsoft.icon              "access plus 1 week"
    ExpiresByType image/x-icon                          "access plus 1 week"

  # HTML
    ExpiresByType text/html                             "access plus 0 seconds"

  # JavaScript
    ExpiresByType application/javascript                "access plus 1 year"
    ExpiresByType application/x-javascript              "access plus 1 year"
    ExpiresByType text/javascript                       "access plus 1 year"

  # Manifest files
    ExpiresByType application/manifest+json             "access plus 1 year"

    ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
    ExpiresByType text/cache-manifest                   "access plus 0 seconds"

  # Media files
    ExpiresByType audio/ogg                             "access plus 1 month"
    ExpiresByType image/bmp                             "access plus 1 month"
    ExpiresByType image/gif                             "access plus 1 month"
    ExpiresByType image/jpeg                            "access plus 1 month"
    ExpiresByType image/png                             "access plus 1 month"
    ExpiresByType image/svg+xml                         "access plus 1 month"
    ExpiresByType image/webp                            "access plus 1 month"
    ExpiresByType video/mp4                             "access plus 1 month"
    ExpiresByType video/ogg                             "access plus 1 month"
    ExpiresByType video/webm                            "access plus 1 month"

  # Web fonts

    # Embedded OpenType (EOT)
    ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
    ExpiresByType font/eot                              "access plus 1 month"

    # OpenType
    ExpiresByType font/opentype                         "access plus 1 month"

    # TrueType
    ExpiresByType application/x-font-ttf                "access plus 1 month"

    # Web Open Font Format (WOFF) 1.0
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/x-font-woff               "access plus 1 month"
    ExpiresByType font/woff                             "access plus 1 month"

    # Web Open Font Format (WOFF) 2.0
    ExpiresByType application/font-woff2                "access plus 1 month"

  # Other
    ExpiresByType text/x-cross-domain-policy            "access plus 1 week"

Redirect 301 /category/31/bespoke-banquette-seating /category/29/banquette-seating

我已在底部添加了重定向,但该功能无法正常工作并打破网站

任何帮助,非常感谢!

1 个答案:

答案 0 :(得分:0)

实际上,您使用// parse those flags which may be provided by users private static Flags parse(char c) { switch (c) { case '-': return LEFT_JUSTIFY; case '#': return ALTERNATE; case '+': return PLUS; case ' ': return LEADING_SPACE; case '0': return ZERO_PAD; case ',': return GROUP; case '(': return PARENTHESES; case '<': return PREVIOUS; default: throw new UnknownFormatFlagsException(String.valueOf(c)); } } 来匹配此mod_rewritecat的任何URI开头,因此该类别会在每个RewriteRule ^cat\/?中匹配,因为这样可以匹配所有内容除非在之前的所有RewriteRule ^(.*)$规则中排除其中的URI,否则最后一条规则将不匹配。

保存原始.htaccess文件并删除最后一条规则,然后在此行mod_rewrite和此Deny from all接受编码# Force compression for mangled之间删除以下规则:

request headers

清除浏览器缓存测试。