Apache - 如何在调试 htaccess 时禁用浏览器缓存

发布于 2024-12-09 06:03:18 字数 471 浏览 1 评论 0原文

我正在尝试调试 .htaccess 文件。 FireFox 不断缓存重定向,我无法绕过它们。通常我会按 Ctrl + F5,但因为它已经将我重定向到另一个页面,所以只会刷新我发送到的页面,而不是我输入的 url。有没有办法强制刷新 url?

下面是一个示例:

  • 将 example.com/hi 重定向到 example.com/hello,在 FireFox 中测试,它可以工作
  • 从 .htaccess 中删除此行
  • 在 FireFox 中键入 example.com/hi,它仍然重定向到 example.com/hello
  • 键入 example。 com/hi 在 Chrome 中,它不会重定向

这就是为什么我认为这是浏览器缓存问题,而不是服务器缓存问题。

编辑:这似乎是 FireFox 特有的,一个快速的解决方案是使用 Chrome。缓存在一小时后过期,这在尝试调试时太长了。

I'm trying to debug an .htaccess file. FireFox keeps caching redirects and I can't get around them. Normally I would hit Ctrl + F5, but because it has already redirected me to another page, that just refreshes the page I was sent to and not the url I typed in. Is there a way to force a refresh of a url?

Here's an example:

  • Redirect example.com/hi to example.com/hello, test in FireFox and it works
  • Remove this line from .htaccess
  • Type example.com/hi in FireFox, it still redirects to example.com/hello
  • Type example.com/hi in Chrome, it does not redirect

This is why I think it's a browser caching issue, not server caching.

Edit: This seems to be FireFox specific, a quick solution is to use Chrome instead. The cache expired after an hour, which is way too long when trying to debug.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

粉红×色少女 2024-12-16 06:03:18

如果您使用 RewriteRule,只需使用 R 而不是 R=301。出于其他目的,每当更改重定向时,您都必须清除浏览器缓存。 (如果您不知道如何清除浏览器缓存,谷歌搜索操作方法应该会提供快速而简单的答案 - 或者随时发表评论,我会帮助您。)

简单地说,无论在哪里,都尽量避免 301直到您的重定向正常工作为止。如果您无法避免它们,请准备好定期清除浏览器缓存。

If you're using RewriteRule, just use R instead of R=301. For other purposes, you'll have to clear your browser cache whenever you change a redirect. (If you don't know how to clear your browser cache, googling for a how-to should provide a quick and easy answer - or feel free to comment and I'll help you out.)

Simply put, try to avoid 301s wherever possible until you've got your redirects working normally. If you can't avoid them, get ready to clear your browser cache regularly.

人间不值得 2024-12-16 06:03:18

清除 Firefox 的网络缓存对我有用。也适用于 301 重定向。

首选项/选项 >高级>网络>缓存的网页内容。

清除 Firefox 偏好设置中的网络缓存

请参阅 https://support.mozilla.org/en-US/kb/how-clear-firefox-cache

Clearing the Firefox' network cache works for me. Also for 301 redirects.

Preferences/Options > Advanced > Network > Cached web content.

Clear network cache in Firefox preferences

See https://support.mozilla.org/en-US/kb/how-clear-firefox-cache

无人接听 2024-12-16 06:03:18

在 Google Chrome 中,使用以下命令以“隐身”模式打开一个新选项卡:

CTRL-SHIFT-N

对于调试非常有用。

In Google Chrome, open a new tab in "Incognito" mode using:

CTRL-SHIFT-N

Very useful for debugging.

谢绝鈎搭 2024-12-16 06:03:18

我认为值得在这里权衡,以防我的经验对任何人有帮助。我经常在本地计算机上的开发和生产分支之间来回切换。开发分支是我的本地环境,生产分支是我的远程服务器。两个环境之间的唯一区别是 .htaccess 文件。我的远程服务器需要重写规则,以防有人不在 URL 前输入“www”:

# If www is missing from the beginning of the URL
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

但是,由于 URL 结构,此重写规则不适用于我的本地环境。因此,在我的本地版本的 .htaccess 中,我注释掉了重写规则。

我注意到 Chrome 似乎并没有每次都去我的本地服务器获取最新的 .htaccess 文件。它显然正在缓存重写,因为当我从生产分支切换到开发分支时,我得到如下所示的内容:

www.www-local.myurl.local

如果我使用 Safari,我会得到正确的 URL:

www-local.myurl.local

要解决此 Chrome 问题,我转到了开发人员工具 > >设置>一般>并选中“禁用缓存(当 DevTools 打开时)”

选中此选项后,我只需打开开发工具并重新加载即可获取当前的 .htaccess。

I think it's worth weighing in here just in case my experience helps anyone. I regularly switch back and forth between a development and production branch on my local machine. The development branch is my local environment and the production branch is for my remote server. The only difference between the two environments is the .htaccess file. My remote server needs a rewrite rule in case someone does not enter "www" before the URL:

# If www is missing from the beginning of the URL
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

However, this rewrite rule does not work for my local environment because of the URL structure. So in my local version of .htaccess I comment out the rewrite rules.

What I've noticed is that Chrome does not seem to go to my local server to get the latest .htaccess file every time. It's obviously caching the rewrite because when I switch from my production branch to my development branch I get something that looks like this:

www.www-local.myurl.local

If I use Safari, I get the correct URL:

www-local.myurl.local

To resolve this Chrome issue, I went to the Developer Tools > Settings > General > and check "Disable cache (while DevTools is open)"

With this checked, I just need to open Dev Tools and reload to get the current .htaccess.

作业与我同在 2024-12-16 06:03:18

要强制清除 Google Chrome 中的 htaccess/重定向缓存:

  1. 转至“设置”>“高级>隐私>清除浏览数据
  2. 选择“缓存的图像和文件”
  3. 单击清除浏览数据

您的页面现在应该加载新的 htaccess 设置。

To force clear htaccess/redirect caches in Google Chrome:

  1. Go to Settings > Advanced > Privacy > Clear Browsing Data
  2. Select "Cached Images and Files"
  3. Click Clear Browsing Data

Your page should now load the fresh htaccess settings.

怼怹恏 2024-12-16 06:03:18

在 Firefox 中,按选项命令 I 打开开发人员工具栏。然后点击设置(它是一个小齿轮图标),并在高级设置下勾选禁用 HTTP 缓存(当工具箱打开时)。这对我来说很有效。

In Firefox open Developer Toolbar by pressing Option Command I. Then click Settings (It's a little cog icon) and under Advanced Settings put a tick next to Disable HTTP Cache (when toolbox is open). This did the trick for me.

浴红衣 2024-12-16 06:03:18

在 Chrome 中,您可以在开发者工具面板

Command+Option+C (Mac) or Control+Shift+C (Windows, Linux, Chrome OS).

中 禁用浏览器缓存在网络选项卡中,您可以找到禁用缓存复选框。
它仅在开发人员工具面板打开时有效。
输入图片此处描述

In Chrome, you can disable browser cache in the Developer Tools panel

Command+Option+C (Mac) or Control+Shift+C (Windows, Linux, Chrome OS).

In the Network tab, you can find Disable cache checkbox.
It only works while the Developer Tools panel is open.
enter image description here

睫毛溺水了 2024-12-16 06:03:18

我终于找到了 Chrome 的解决方案:

disable cache

在 Web Developer 中,打开选项卡“网络”并启用“禁用缓存”。

这对我有用。

I finally found a solution for Chrome:

disable cache

In the Web Developer, open Tab "Network" and enable "Disable cache".

This worked for me.

天赋异禀 2024-12-16 06:03:18

在尝试无数次刷新我的缓存后,我决定清除我网站的 cookie,我不知道为什么或如何,但这为我清除了它。也许这是 Magento 特有的东西,但也可能更通用。

After trying to refresh my cache countless times I decided to clear the cookies for my site, I don't know why or how but that cleared it for me. Maybe it's something specific to Magento but it might be more general.

桃扇骨 2024-12-16 06:03:18

在 Google Chrome 中打开开发者工具栏。然后单击“设置”(它是一个 3 点图标),并在“网络”部分下,选中“禁用缓存(当 DevTools 打开时)”。

In Google Chrome open Developer Toolbar. Then click Settings (It's a 3 dots icon) and under Network section, check on "Disable cache (while DevTools is open)".

最后的乘客 2024-12-16 06:03:18

对于 Chrome,您可以在每个页面上执行此操作,而无需清除所有浏览器缓存;只需打开开发工具(您可以使用快捷键 ctrl + shift + I)。打开后,右键单击重新加载图标,然后单击“清空缓存并硬重新加载”。
输入图片此处描述

For chrome, you can do this per-page without clearing out all browser cache; just open the develop tools (You can use shortcut ctrl + shift + I). Once it comes open, right click on the reload icon and click "Empty cache and hard reload".
enter image description here

最笨的告白 2024-12-16 06:03:18

那么,您可以使用 Firefox 插件 Clear Cache 简单地清除您的 htaccess 缓存。比任何 CTRL + R

https://addons.mozilla 更好。 org/en-US/firefox/addon/clear-cache-button/

Well, you can simply clear your htaccess cache using Firefox addon Clear Cache. Better than any CTRL + R

https://addons.mozilla.org/en-US/firefox/addon/clear-cache-button/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文