我似乎遇到了一个奇怪的问题,它只发生在一台机器上,而不是另一台机器上,这台机器上的Apache2版本是2.4.23(不工作的版本),而在工作的机器上,我有Apache2.4.10版本。
我所拥有的重写片段将没有扩展名的url重定向到.html(如果文件存在并如下所示)
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L,QSA]
我删除了这一部分,重定向循环停止,但显然我的无扩展url不再被重定向。
我已经把它发展到了这个阶段,我认为这肯定会阻止重定向问题,但仍然会永远循环
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_FILENAME} !\.html$
RewriteRule ^(.*?)/?(?!\.html/)$ $1.html [L,QSA]
在所讨论的apache服务器上启用调试日志级别会产生大量类似于此级别的行
[Wed May 30 11:49:25.669176 2018] [rewrite:trace3] [pid 4292] mod_rewrite.c(477): [client xx.xx.xxx.xxx:63613] xx.xx.xxx.xxx - - [domain.com/sid#7f30066c1328][rid#7f2fff7d5718/initial/redir#9] [perdir /domains/domain.com/public_html/] applying pattern '^(.*)$' to uri '2012/06/some-blog-post/privacy.html.html.html.html.html.html.html.html.html'
[Wed May 30 11:49:25.669200 2018] [rewrite:trace3] [pid 4292] mod_rewrite.c(477): [client xx.xx.xxx.xxx:63613] xx.xx.xxx.xxx - - [domain.com/sid#7f30066c1328][rid#7f2fff7d5718/initial/redir#9] [perdir /domains/domain.com/public_html/] add path info postfix: /domains/domain.com/public_html/2012/06/some-blog-post -> /domains/domain.com/public_html/2012/06/some-blog-post/privacy.html.html.html.html.html.html.html.html.html
[Wed May 30 11:49:25.669215 2018] [rewrite:trace3] [pid 4292] mod_rewrite.c(477): [client xx.xx.xxx.xxx:63613] xx.xx.xxx.xxx - - [domain.com/sid#7f30066c1328][rid#7f2fff7d5718/initial/redir#9] [perdir /domains/domain.com/public_html/] strip per-dir prefix: /domains/domain.com/public_html/2012/06/some-blog-post/privacy.html.html.html.html.html.html.html.html.html -> 2012/06/some-blog-post/privacy.html.html.html.html.html.html.html.html.html
恐怕我对htaccess语法不是很精通,所以我可能遗漏了一些显而易见的东西
这是整个htaccess文件(抱歉有点长)
RedirectMatch 301 ^/quote/?$ /pricing
RedirectMatch 301 ^/order\.htm/?$ /order
RedirectMatch 301 ^/contact\.htm/?$ /contact
RedirectMatch 301 ^/coin-gallery\.htm/?$ /gallery
RedirectMatch 301 ^/gallery-html/?$ /gallery
RedirectMatch 301 ^/baseball-html/?$ /baseball-trading-pins
RedirectMatch 301 ^/softball-html/?$ /baseball-trading-pins
RedirectMatch 301 ^/volleyball-html/?$ /baseball-trading-pins
RedirectMatch 301 ^/basketball-html/?$ /baseball-trading-pins
RedirectMatch 301 ^/football-html/?$ /baseball-trading-pins
RedirectMatch 301 ^/soccer-html/?$ /baseball-trading-pins
RedirectMatch 301 ^/hockey-html/?$ /baseball-trading-pins
##blogs-500s
RedirectMatch 301 ^/tag.*$ /blog
RedirectMatch 301 ^/wp.*$ /blog
RedirectMatch 301 ^/category\/.*$ /blog
RedirectMatch 301 ^/[^a-zA-Z]+$ /blog
##pins
RedirectMatch 301 ^/sitemap-html/?$ /
RedirectMatch 301 ^/quote_lapelpins\.html/?$ /
RedirectMatch 301 ^/custom-html/?$ /custom-lapel-pin-styles
RedirectMatch 301 ^/softenamel-html/?$ /soft-enamel-pins
RedirectMatch 301 ^/cardstock-html/?$ /cardstock
RedirectMatch 301 ^/employee-html/?$ /employee-recognition-pins
RedirectMatch 301 ^/employee-recognition/?$ /employee-recognition-pins
RedirectMatch 301 ^/baseball-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/softball-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/volleyball-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/basketball-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/football-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/usssaquote_tradingpins\.html/?$ /custom-usssa-trading-pins?lid=Ij2
RedirectMatch 307 ^/soccer-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/hockey-html/?$ /baseball-trading-pins
RedirectMatch 307 ^/cloisonne-html/?$ /cloisonne-pins
RedirectMatch 301 ^/pin-pricing/?$ /pricing
RedirectMatch 301 ^/rush-pins-2/?$ /rush-pins
RedirectMatch 301 ^/baseball\.html/?$ /baseball-trading-pins
RedirectMatch 307 ^/softball\.html/?$ /baseball-trading-pins
RedirectMatch 307 ^/soccer\.html/?$ /baseball-trading-pins
RedirectMatch 307 ^/volleyball\.html/?$ /baseball-trading-pins
RedirectMatch 307 ^/basketball\.html/?$ /baseball-trading-pins
RedirectMatch 307 ^/football\.html/?$ /baseball-trading-pins
RedirectMatch 307 ^/hockey\.html/?$ /baseball-trading-pins
RedirectMatch 301 ^/contactus-html/?$ /contact
RedirectMatch 301 ^/aboutus-html/?$ /about-us
RedirectMatch 301 ^/aboutus\.html/?$ /about-us
RedirectMatch 301 ^/aboutus\.htm/?$ /about-us
RedirectMatch 301 ^/termsandconditions-html/?$ /terms
RedirectMatch 301 ^/termsandconditions\.html/?$ /terms
RedirectMatch 301 ^/privacy-htm/?$ /privacy
RedirectMatch 301 ^/presentation\.html/?$ /presentation-options
RedirectMatch 301 ^/presentation-html/?$ /presentation-options
RedirectMatch 301 ^/attachments\.html/?$ /attachments
RedirectMatch 301 ^/attachments-html/?$ /attachments
RedirectMatch 301 ^/platingchart\.html/?$ /plating
RedirectMatch 301 ^/platingchart-html/?$ /plating
RedirectMatch 301 ^/gemstones\.html/?$ /gemstones
RedirectMatch 301 ^/trading-pin-options/?$ /baseball-trading-pins
RedirectMatch 301 ^/trading-pin-gallery/?$ /gallery
RedirectMatch 301 ^/trading-pin-gallery-2/?$ /gallery
RedirectMatch 301 ^/trading-pin-gallery-3/?$ /gallery
RedirectMatch 301 ^/trading-pin-gallery-4/?$ /gallery
RedirectMatch 301 ^/artwork\.html/?$ /artwork
RedirectMatch 301 ^/artwork-html/?$ /artwork
RedirectMatch 301 ^/keychains-html/?$ /keychains
RedirectMatch 301 ^/challengecoins-html/?$ /custom-challenge-coins
RedirectMatch 301 ^/medallions-html/?$ /medals-medallions
RedirectMatch 301 ^/wristbands-html/?$ /custom-wristbands
RedirectMatch 301 ^/lanyards-html/?$ /lanyards
RedirectMatch 301 ^/quote_tradingpins\.html/?$ /custom-usssa-trading-pins?lid=Ij2
RedirectMatch 301 ^/usssa-pins/?$ /custom-usssa-trading-pins?lid=Ij2
RedirectMatch 301 ^/contactus\.html/?$ /contact
RedirectMatch 301 ^/fraternitysorority-html/?$ /fraternity-and-sorority-pins
##coins
RedirectMatch 301 ^/coin-bottle-openers\.htm/?$ /coin-bottle-openers
RedirectMatch 301 ^/coin-gallery\.htm/?$ /gallery
RedirectMatch 301 ^/coin-gallery.*$ /gallery
RedirectMatch 301 ^/coin-pricing\.htm/?$ /pricing
RedirectMatch 301 ^/create\.htm/?$ /create
RedirectMatch 301 ^/presentation.htm/?$ /coin-presentation-options
RedirectMatch 301 ^/history\.htm/?$ /challenge-coin-history
RedirectMatch 301 ^/faq\.htm/?$ /faq
RedirectMatch 301 ^/testimonials\.htm/?$ /testimonials
RedirectMatch 301 ^/quote/?$ /create
RedirectMatch 301 ^/quote/view(\.php)?$ /view
##patches
RedirectMatch 301 ^/pvc-patches/?$ /pvc
<Files "header.php">
Order Allow,Deny
Deny from all
</Files>
<Files "footer.php">
Order Allow,Deny
Deny from all
</Files>
<Files "config.php">
Order Allow,Deny
Deny from all
</Files>
<Files "version">
Order Allow,Deny
Deny from all
</Files>
<Files "superheader.php">
Order Allow,Deny
Deny from all
</Files>
Options -Indexes
ErrorDocument 404 /404.html
ErrorDocument 500 /505.html
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1/$1 [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule ^(.*?)/?$ $1.php [L,QSA]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_FILENAME} !\.html$
RewriteRule ^(.*?)/?(?!\.html/)$ $1.html [L,QSA]
RewriteRule ^/?img/([A-Fa-f0-9]{64}).gif$ /scripts/trackemail.php?id=$1 [QSA,L]
编辑2
哎呀!我忘记了url,这应该是我列出的第一件事,但是这个例子中的路径应该是
/2012/06/一些博客文章/隐私
这是加载该url时的apache2响应头
HTTP/1.1 500 Internal Server Error
Date: Wed, 06 Jun 2018 14:54:45 GMT
Server: Apache
Content-Length: 666
Connection: close
Content-Type: text/html; charset=iso-8859-1
在启用调试日志级别之后,我获取了更多的Apache2日志,并将其放在这里
https://pastebin.com/pu5sUJnG
,添加
LogLevel alert rewrite:trace3
到我的apache2.conf文件