[noparse]Original URL…
http://www.domain.com/index.php?v=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZZZZZZZ
URL Wanted.
htp://www.domain.com/v/ZZZZZZZ/
I got
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^v/([^.]+)/$ index.php?v=$1 [L]
RewriteCond %{QUERY_STRING} ^v=http%3A%2F%2Fwww.youtube.com %2Fwatch%3Fv%3D([^/]+)?$
RewriteRule ^index\.php$ http://www.domain.com/v/([^/]+)/ [R=301,L]
which does a little URL change, to
domain.com/v/([^&]+)/?v=http%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253D9lp0IWv8QZY
The non-encoded version…
RewriteCond %{QUERY_STRING} ^v=http://www.youtube.com/watch?v=([^&]+)?$
RewriteRule ^index\.php$ http://www.domain.com/v/([^&]+)/ [R=301,L]
does nothing.
[/noparse]
Now this works!!
[noparse]RewriteCond %{THE_REQUEST} +\ /index\.php\?v=http\%3A\%2F\%2Fwww\.youtube\.com\%2Fwatch\%3Fv\%3D([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/v/%1/ ? [R=301,L]
RewriteCond %{THE_REQUEST} +\ /index\.php\?v=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/v/%1/ ? [R=301,L]
RewriteRule ^v/([^.]+)/$ index.php?v=$1 [L][/noparse]
dklynn
February 18, 2010, 9:13am
3
Nintendo,
Aw, how can that work? You’ve got ILLEGAL characters all over the place!
IMHO, the best thing for you to do is to eliminate the protocol from the query string (the http:// bit) and add that back in with your index.php script (or whatever you’re using). In addition, parsing {THE_REQUEST} is a nasty bit of work (especially for mod_rewrite).
Regards,
DK