各种 htaccess 重定向方法以及为什么?
我有一个过时的 url (mydomain.com/page.html),它自然会返回 404 错误。我想实施永久 301 重定向回我的主页 mydomain.com。 (具有手动编辑 htaccess 文件权限的 Apache/Linux 服务器)
我想遵守 Google 的要求,使用 301 重定向旧页面。
三种方法有效,但哪一种最好,为什么?优点与优点缺点,如果有的话?
1- 这是 cPanel 自动写入的内容(似乎有点过头了)...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^page\.html$ "http\:\/\/www\.mydomain\.com" [R=301,L]
2- 这是我过去使用过的...
Redirect permanent /page.html http://www.mydomain.com
3- 我想知道这是否是最好的...
Redirect 301 /page.html http://www.mydomain.com
谢谢您的意见!
I have an obsolete url (mydomain.com/page.html) which naturally returns a 404 error. I want to implement a permanent 301 redirect back to my home page at mydomain.com. (Apache/Linux server with permission to manually edit htaccess file)
I want to be compliant with Google's requirement to have old pages redirected with a 301.
Three methods work but which one is the best and why? Pros & cons, if any?
1- This is what cPanel writes automatically (seems like overkill)...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^page\.html$ "http\:\/\/www\.mydomain\.com" [R=301,L]
2- This is what I've used in the past...
Redirect permanent /page.html http://www.mydomain.com
3- I'm wondering if this is best...
Redirect 301 /page.html http://www.mydomain.com
Thank-you for your opinions!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案#1 使用 mod_rewrite 并且会更慢。 #2 和 #3 之间没有区别 - 都使用 mod_alias 并且应该比 #1 更快。
Solution #1 uses mod_rewrite and will be slower. There is no difference between #2 and #3 - both use mod_alias and should be faster than #1.