问题描述
在实现.htaccess文件后,使我的网站的单个页面可以通过简单的 / folder / 链接访问,某些(如果不是全部)页面将加载两次。
After implementing an .htaccess-file in order to make the single pages of my website accessible with simple /folder/ links, certain (if not all) pages load twice.
每当我访问该页面时,当计数器计算出我网站上某个特定内容的点击次数时,我便注意到了这一点。
I noticed this when a counter that counts the number of clicks a certain content on my site gets, incremented twice, whenever I visited the page.
这仅是在创建.htaccess文件之后发生的。
This only happened after I created the .htaccess-file.
这是一个普遍的问题还是我唯一遇到此问题?
Is this a common problem or am I the only one experiencing this? What is there to be done in order to prevent this?
除了某些重写条件外,.htaccess文件中没有任何内容...
Besides some rewrite conditions, there's nothing in my .htaccess-file ...
AddDefaultCharset UTF-8
RewriteEngine on
#remove PHPSESSID
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]
#content
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?(content)/([0-9]+)/(.+)$ index.php?nav=single&ID=$2 [QSA,L]
#comments
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?(comments)/([0-9]+)/([0-9]+)$ index.php?nav=comments&ID=$2&catID=$3 [QSA,L]
#normal pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)$ index.php?nav=$1 [QSA,L]
# compress text, html, javascript, css, xml:
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
推荐答案
在重定向之前,计数器会增加,可能有多种原因。原因之一是对外部资源使用绝对路径。它们也会被重写,并可能导致问题。
The counter is incremented before the redirect, could be a variety of reasons. One reason is using absolute paths for external resources. They will be rewritten too, and potentially cause problems.
这里有个主意:
在< head>模板的标签:
add this in between the < head> tags of the template:
<base href="/">
如果这不起作用,请尝试将计数器功能移至输出之前的最后几行缓冲区将被清除。
If that doesn't work, try moving the counter function to the very last few lines before the output buffer would be cleared.
这篇关于实施.htaccess后,我的网站加载了两次,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!