mod_rewrite正在重定向浏览器而不是重写
我正在使用以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在看到了问题所在。您正在将 URL 从
http://www.example.com/
重写为http://www.example.com/shows
。由于/shows
是一个目录而不是文件,Apache 在重写后发送一个尾部斜杠重定向。以下是解决方法:注意:由于 Apache 可能之前发送了 301 Moved Permanently 标头,浏览器将缓存此响应,即使您对 . .htaccess 文件。测试时经常清除浏览器缓存。
I now see the problem. You are rewriting a URL from
http://www.example.com/
tohttp://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: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.
我很久以前就想知道同样的问题,所以我决定在谷歌上搜索,发现了你的问题。我意识到有两个选项“重定向”和“重新映射”。所以我认为这是理解你所问内容的关键。基本上,有两个选项
重定向而不改变 url
& 。以及重定向更改浏览器上的 url。
无论如何,请看这里
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
& and redirection changing the url on the browser.
Anyway, take a look here
http://httpd.apache.org/docs/2.2/rewrite/remapping.html