各种 htaccess 重定向方法以及为什么?

发布于 2024-10-31 10:01:22 字数 674 浏览 9 评论 0原文

我有一个过时的 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 技术交流群。

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

发布评论

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

评论(1

濫情▎り 2024-11-07 10:01:22

解决方案#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.

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