Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess Redirect BEFORE RewriteRule?

Tags:

.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>

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

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

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

like image 320
Jason Axelrod Avatar asked Dec 28 '12 19:12

Jason Axelrod


People also ask

What is RewriteRule in htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.


1 Answers

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.

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>
like image 50
Jon Lin Avatar answered Nov 09 '22 23:11

Jon Lin