.htaccess: How can I keep the same the URL, but di

2019-09-20 03:05发布

How can I keep the same the URL, but display a different page on the server using .htaccess rewrite rule? I'm working on hotlink protection. The playlist is generated with the following link: http://site.com/get.playlist.php?

the full link:

http://site-1.com/get.playlist.php?playlist=http://site.com/video/34141ce7760f58f0c3eb5e0c758afb69/pl/playlist.txt&hash=34141ce7760f58f0c3eb5e0c758afb69

i would like to redirect the link from

http://site-2.com/video/34141ce7760f58f0c3eb5e0c758afb69/pl/playlist.txt

to

http://site-1.com/get.playlist.php?playlist=http://site.com/video/34141ce7760f58f0c3eb5e0c758afb69/pl/playlist.txt&hash=34141ce7760f58f0c3eb5e0c758afb69

1条回答
聊天终结者
2楼-- · 2019-09-20 03:58

That would be something like:

 RewriteRule ^video/(\w+)/(\w+)/(\w+)$ http://site-1.com/get.playlist.php?playlist=http://site.com/video/$1/$2/$3&hash=$1

Although that would probably result in an invalid url, you would need to url encode the characters like : and / in the query string.

An additional problem is that the redirect is to a different domain, so the url would probably change in the browser address bar.

Is it really on a different domain, as your question title seems to imply otherwise?

If not, you can change it to:

 RewriteRule ^video/(\w+)/(\w+)/(\w+)$ /get.playlist.php?playlist=http://site.com/video/$1/$2/$3&hash=$1
查看更多
登录 后发表回答