Mian Shahzeb
Mian Shahzeb

Reputation: 35

htaccess URL redirect for YouTube

I am trying to Redirect one url to another. Maybe this is common question or asked many times before but i am confused and couldn't find. Please take a look at this for example,

Reffering url is

example.com/folder1/watch=?id

I want to redirect it to another domain with .htaccess (htaccess file shall be in folder1. Now .htaccess should pick the string "watch=?id" and put after second domain like this.

example2.com/folder1/watch=?id (watch id should be that which was in refering url.)

Basic concept, I want to download youtube video through .htaccess URL redirecting option.

Upvotes: 0

Views: 1091

Answers (1)

ahPo
ahPo

Reputation: 384

Try this. The parameter name should be "v" instead "id" on the referring url to play the proper video under youtube.

The rule redirects to "youtube.com/watch" URL with all the referring request parameters appended to it.

    Options +FollowSymLinks
    RewriteEngine On
    # if requested file exists use it 
    RewriteCond %{REQUEST_FILENAME} !-f
    # if requested directory exists use it
    RewriteCond %{REQUEST_FILENAME} !-d
    # otherwise redirect to "https://www.youtube.com/watch" 
    # appended with the params of the requested URI
    RewriteRule ^.*\/watch\?*$ https://www.youtube.com/watch [L,QSA]
    RewriteRule ^watch\?*$ https://www.youtube.com/watch [L,QSA]

Upvotes: 1

Related Questions