检查cookie值并重写

时间:2017-09-05 09:11:11

标签: php apache mod-rewrite cookies

我已经打开了一个关于这个主题的帖子,但是我写得非常糟糕你可以在这里找到,我也尝试过使用PHP header(),现在我正在尝试使用setcookie(): Apache Rewrite only if PHP didn't set header()

这就是我所拥有的:

的index.php

<?php
    if(isset($_GET['ac'])){
        $ac = $_GET['ac'];
        if(isset($_COOKIE['value']) && $_COOKIE['value'] == "pass"){
            header("Location: https://" . $ac);
        } else {
            sleep(5);
            setcookie("value","pass");
            header("Location: https://filter.bernardo.fm/?ac=" . $ac);
            exit();
        }
     } else {
         echo "Direct access to the Filter is forbidden.";
     }
 ?>

启用Apache站点

<VirtualHost *:80>
    ServerName filter.bernardo.fm
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^filter.bernardo.fm
    RewriteRule (.*) https://filter.bernardo.fm/?ac=%{HTTP_HOST}%{REQUEST_URI}
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://filter.bernardo.fm/?ac=%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
    ServerName filter.bernardo.fm
    RewriteEngine On
    <If "true">
    RewriteCond %{HTTP_COOKIE} !value=pass [NC]
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    </If>
    <Else>
    RewriteCond %{HTTP_HOST} !^filter.bernardo.fm
    RewriteRule (.*) https://filter.bernardo.fm/?ac=%{HTTP_HOST}%{REQUEST_URI}
    </Else>
    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/filter.bernardo.fm/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/filter.bernardo.fm/privkey.pem
    DocumentRoot /var/www/filter/
    ErrorDocument 404 /error404.php
</VirtualHost>

所以,我想要的是,当没有设置cookie时,它会被重定向到filter.bernardo.fm,在那里设置cookie并将该人重定向到他/她想去的网站,例如, bernardo.fm

此时我正被重定向,直到Chrome“太多重定向”出现错误。

我希望你能帮助我,我希望你能理解我到目前为止所做的以及我想要存档的内容。

祝贺BERNARDO

0 个答案:

没有答案