htaccess在RewriteRule之前重定向? [英] htaccess Redirect BEFORE RewriteRule?

查看:82
本文介绍了htaccess在RewriteRule之前重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的htaccess:

This is my htaccess:

## Rewrites
<IfModule mod_rewrite.c>
    RewriteEngine On

    Redirect /stream/ http://twitch.tv/8wayrun
    Redirect /stream http://twitch.tv/8wayrun

    RewriteCond %{HTTP_HOST} ^(www\.)?8wayrun\.com$
    RewriteRule ^(.*)$ http://8wayrun.com/calibur/$1 [R=302,L]
</IfModule>

基本上,我需要将8wayrun.com/stream重写为twitch.tv/8wayrun ...

Basically, I need to to rewrite 8wayrun.com/stream to twitch.tv/8wayrun...

然后我需要它将8wayrun.com重写为8wayrun.com/calibur ...

And then I need it to rewrite 8wayrun.com to 8wayrun.com/calibur...

问题是,它将8wayrun.com/stream重写为8wayrun.com/calibur/stream。我该如何解决?

The problem is, its rewriting 8wayrun.com/stream to 8wayrun.com/calibur/stream. How do I fix this?

推荐答案

重定向指令是其中的一部分mod_alias和 Rewrite * 指令是mod_rewrite的一部分。当通过URL /文件映射管道处理URI时,两个模块都将被应用,因此一个模块在另一个模块的前面无所谓,两个模块都将在最后应用。

The Redirect directive is part of mod_alias, and the Rewrite* directives are part of mod_rewrite. When a URI gets processed through the URL/file mapping pipeline, both modules get applied so having one in front of the other doesn't matter, both will get applied in the end.

最好只使用mod_rewrite并使用 L 标志来防止应用额外的重定向。

You're better off sticking with only mod_rewrite and using the L flag to prevent the extra redirects from geting applied.

## Rewrites
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^/?stream/? http://twitch.tv/8wayrun [R=302,L]

    RewriteCond %{HTTP_HOST} ^(www\.)?8wayrun\.com$
    RewriteRule ^(.*)$ http://8wayrun.com/calibur/$1 [R=302,L]
</IfModule>

这篇关于htaccess在RewriteRule之前重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆