.htaccess redirect unless in iframe

2019-07-12 02:10发布

When creating websites, I like to let my clients view the work in progress. At the moment I do this by uploading their website to a directory, and use .htaccess to password protect that directory. But keeping track of passwords and ensuring the directory is still protected after an update is becoming an issue.

I have now created a user login system for my clients where they can login and be redirected to a preview of their site (in an iframe on the page preview.php?c=clientName).

I have looked into various ways of redirecting the client site to the preview page and the easiest has been using .htaccess, but this redirect still affects the site when in an iframe.

Is there any way to stop the .htaccess redirect when the site is in an iframe?

1条回答
冷血范
2楼-- · 2019-07-12 02:50

You could test against the "Referer" header, you can't really rely on that but it's the best possible.

E.g. http://jsfiddle.net/QmnKR/

one of the headers will be Referer: http:// fiddle.jshell.net/QmnKR/show/light/

查看更多
登录 后发表回答