mod_rewrite正在重定向浏览器而不是重写

发布于 2024-12-08 08:04:31 字数 444 浏览 1 评论 0原文

我正在使用以下 mod_rewrite 从我的网站的顶级目录重定向到子目录 shows/

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^$ shows [L]

重定向运行良好。但是,URL 显示重定向,我相信如果您使用 mod_rewrite 则不应显示重定向。

澄清一下:指向 http://www.example.com/ 的浏览器被重定向到子目录 shows/。但浏览器将 URL 中的重定向显示为 http://www.example.com/shows/。同样,我的理解是,通过使用 mod-rewrite,您可以使重定向不可见,因此用户不知道重定向已经发生。

我做错了什么吗?

I am using the following mod_rewrite to redirect from the top directory of my site, to the subdirectory shows/:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^$ shows [L]

The redirect is performing fine. However, the URL is displaying the redirect, which I believe it should not if you use mod_rewrite.

To clarify: A browser pointed towards http://www.example.com/ is redirected to the subdirectory shows/. But the browser displays the redirect in the URL as http://www.example.com/shows/. Again, it is my understanding that by using mod-rewrite, you make the redirect invisible, so the user is not aware the redirect has taken place.

Am I doing something wrong?

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

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

发布评论

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

评论(2

原来分手还会想你 2024-12-15 08:04:31

我现在看到了问题所在。您正在将 URL 从 http://www.example.com/ 重写为 http://www.example.com/shows。由于 /shows 是一个目录而不是文件,Apache 在重写后发送一个尾部斜杠重定向。以下是解决方法:

RewriteRule ^$ shows/ [L]
# here -------------^

注意:由于 Apache 可能之前发送了 301 Moved Permanently 标头,浏览器将缓存此响应,即使您对 . .htaccess 文件。测试时经常清除浏览器缓存。

I now see the problem. You are rewriting a URL from http://www.example.com/ to http://www.example.com/shows. Since /shows is a directory and not a file, Apache sends a trailing slash redirect after rewriting. Here is How you fix it:

RewriteRule ^$ shows/ [L]
# here -------------^

Note: since Apache might have sent a 301 Moved Permanently header earlier, browsers will cache this response and it might show you wrong page/content even after you make changes to your .htaccess file. Clear browser cache often when you're testing.

无法言说的痛 2024-12-15 08:04:31

我很久以前就想知道同样的问题,所以我决定在谷歌上搜索,发现了你的问题。我意识到有两个选项“重定向”和“重新映射”。所以我认为这是理解你所问内容的关键。基本上,有两个选项

重定向而不改变 url

RewriteEngine on
RewriteRule ^/foo\.html$ /bar.html [PT]

& 。以及重定向更改浏览器上的 url。

RewriteEngine on
RewriteRule ^/foo\.html$ bar.html [R]

无论如何,请看这里
http://httpd.apache.org/docs/2.2/rewrite/remapping.html

I was wondering the same for a long time ago,so I decided to search on google and I found your question. I realised that there is something like two options "Redirect" and "Remapping". So I think here is the key to understand what you were asking. Basically, there are two options

redirection without change the url

RewriteEngine on
RewriteRule ^/foo\.html$ /bar.html [PT]

& and redirection changing the url on the browser.

RewriteEngine on
RewriteRule ^/foo\.html$ bar.html [R]

Anyway, take a look here
http://httpd.apache.org/docs/2.2/rewrite/remapping.html

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