301重定向问题?
这是页面重定向到另一个域页面的好例子:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据推测,这些规则在功能上是等效的(好吧,假设
http://dejanseo.com.au/blog/spam/
应该是http://dejanseo.com.au/ blog-spam/
就像第一个重定向到的那样,指向该位置的唯一主机是dejanseo.com.au
(带或不带www
)。第一个示例使用
mod_rewrite
中的指令,而第二个使用mod_alias
。我想对于这种特殊情况,首选选项是第二个,不仅因为它更简单(在创建mod_rewrite
使用的正则表达式时还涉及边际额外开销,但这非常次要):但是,我怀疑您拥有第一个的原因是它是使用 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 behttp://dejanseo.com.au/blog-spam/
like the first one redirects to, and the only host pointing at that location isdejanseo.com.au
with or without thewww
).The first example uses directives from
mod_rewrite
, whereas the second one uses some frommod_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 bymod_rewrite
, but that's very minor):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 theRedirect
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 thatmod_rewrite
also allows for internal redirects invisible to the user, whichmod_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).难以置信,问题是合成不正确,所以不是:
它应该看起来像这样:
一个,第一个大字母是所有麻烦的根源,真是浪费时间:D
它现在可以正常工作了!
感谢所有参与的人,问题已解决。
Unbeliavable, the problem was that the synthax wasn't correct, so instead of:
it should look like this:
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.