Search code examples
regex.htaccesshttp-redirecthttp-status-code-301

How can I do a 301 redirect?


i have this code in my htaccess

RewriteRule ^/?watch-([a-zA-Z0-9\-]+)-tvshow-season-([0-9]+)-episode-([0-9]+)-online-free.html$ index.php?menu=episode&perma=$1&season=$2&episode=$3&lang=en [L]

the old one was

RewriteRule ^/?show/([a-zA-Z0-9\-]+)/season/([0-9]+)/episode/([0-9]+)$ index.php?menu=episode&perma=$1&season=$2&episode=$3&lang=en [L]

so i want the old to redirect to the new like this

Redirect 301  /?show/([a-zA-Z0-9\-]+)/season/([0-9]+)/episode/([0-9]+)  /?watch-([a-zA-Z0-9\-]+)-tvshow-season-([0-9]+)-episode-([0-9]+)-online-free.html

Solution

  • Redirect directive doesn't use regex. Use RedirectMatch instead and you have to use back-reference in target URL:

    RedirectMatch 301 ^/show/([a-zA-Z0-9-]+)/season/([0-9]+)/episode/([0-9]+) /watch-$1-tvshow-season-$2-episode-$3-online-free.html