301重定向问题?

发布于 2024-09-18 07:58:26 字数 364 浏览 4 评论 0原文

这是页面重定向到另一个域页面的好例子:

RewriteCond %{HTTP_HOST} ^dejan.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www.dejan.com.au$
RewriteRule ^seo_news_blog_spam\.html$ "http\:\/\/dejanseo\.com\.au\/blog\-spam\/" [R=301,L]

还是很好的旧作品:

301 redirect seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

有什么区别?

Is this qood example of redirection of page to another domain page:

RewriteCond %{HTTP_HOST} ^dejan.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www.dejan.com.au$
RewriteRule ^seo_news_blog_spam\.html$ "http\:\/\/dejanseo\.com\.au\/blog\-spam\/" [R=301,L]

or good old works too:

301 redirect seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

and whats the difference?

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

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

发布评论

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

评论(2

桃扇骨 2024-09-25 07:58:26

据推测,这些规则在功能上是等效的(好吧,假设http://dejanseo.com.au/blog/spam/应该是http://dejanseo.com.au/ blog-spam/ 就像第一个重定向到的那样,指向该位置的唯一主机是 dejanseo.com.au(带或不带 www)。

第一个示例使用 mod_rewrite 中的指令,而第二个使用 mod_alias。我想对于这种特殊情况,首选选项是第二个,不仅因为它更简单(在创建 mod_rewrite 使用的正则表达式时还涉及边际额外开销,但这非常次要):

Redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog-spam/

但是,我怀疑您拥有第一个的原因是它是使用 CPanel 创建的(基于之前在另一个用户的问题中出现的替换中不必要的转义,其中指出 CPanel 是罪魁祸首)。他们使用了 mod_rewrite 选项,因为它提供了 Redirect 指令所没有的条件灵活性,并且我认为这种灵活性在某种程度上反映在用于创建这些选项的任何接口中规则。

您会注意到,在第一个示例中,有一个关于是否根据您的主机名进行重定向的条件,由 RewriteCond 标识。这使您可以执行更强大的重定向,而不仅仅是基于请求路径。请注意,mod_rewrite 还允许用户不可见的内部重定向,而 mod_alias 并不适用于此,但这不是它在此处使用的功能。

最后,从技术上讲,RewriteCond 语句中的主机名应该转义点,因为 . 字符在正则表达式中具有特殊含义。您还可以将它们组合起来,将它们更改为直接字符串比较 ,或者完全删除它们(因为我想它们在这里没有做任何有用的事情)。

Presumably, the rules are functionally equivalent (well, assuming that http://dejanseo.com.au/blog/spam/ was supposed to be http://dejanseo.com.au/blog-spam/ like the first one redirects to, and the only host pointing at that location is dejanseo.com.au with or without the www).

The first example uses directives from mod_rewrite, whereas the second one uses some from mod_alias. I imagine that the preferred option is the second one for this particular case, if not only because it's a bit simpler (there's also marginal additional overhead involved in creating the regular expressions being used by mod_rewrite, but that's very minor):

Redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog-spam/

However, I suspect the reason that you have the first one is that it was created using CPanel (based on the unnecessary escapes in the replacement that appeared before in another user's question where it was indicated CPanel was the culprit). They've gone with the mod_rewrite option because it provides conditional flexibility that the Redirect directive does not, and I assume this flexibility is reflected somewhat in whatever interface is used to create these rules.

You'll note that there is a condition on whether or not to redirect based upon your host name in the first example, identified by the RewriteCond. This allows for you to perform more powerful redirects that are based on more than just the request path. Note that mod_rewrite also allows for internal redirects invisible to the user, which mod_alias is not intended for, but that's not the capacity it's being used in here.

As a final aside, the host names in your RewriteCond statements should technically have their dots escaped, since the . character has special meaning in regular expressions. You could also combine them, change them to direct string comparisons, or remove them altogether (since I imagine they don't do anything useful here).

就是爱搞怪 2024-09-25 07:58:26

难以置信,问题是合成不正确,所以不是:

redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

它应该看起来像这样:

Redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

一个,第一个大字母是所有麻烦的根源,真是浪费时间:D
它现在可以正常工作了!
感谢所有参与的人,问题已解决。

Unbeliavable, the problem was that the synthax wasn't correct, so instead of:

redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

it should look like this:

Redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

One, first big letter was the source of all troubles, what a waste of time :D
it works now as it supposed to!
Thanks to everyone who participated, issue solved.

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