Forum Moderators: phranque
RewriteRule ^(.*)$ https://www.example.com [L,R=301] if ($_GET['foo'])
setcookie('bar', 'something_random');
// I added time() in an attempt to bypass cache
header('Location: https://original.com/?h=' . time());
exit; RewriteCond %{REQUEST_URI} !^/preapprove\.php
RewriteCond %{HTTP_COOKIE} !bar=something_random
RewriteRule ^(.*)$ https://www.example.com [L,R=301] RewriteRule ^(.*)$ https://www.example.com [L,R=301]Surely, surely you meant to say either
RewriteRule (.*) https://www.example.com/$1 [L,R=301]
orRewriteRule ^ https://www.example.com [L,R=301]depending on whether the new site is or isn’t a page-for-page match. Surely, surely you meant to say... RewriteRule ^ https://www.example.com [L,R=301]
It isn’t clear what order all this is happening in. If the cookie is set in preapprove.php, then htaccess won’t know about it until the next time that same page is requested.
Is that pair of RewriteCond meant to be AND-delimited? That is, redirect only if the requested URL is not blahblah and also the cookie does not have the specified value? It kinda seems like it should be OR: redirect unless the request is either for this specific page, OR the cookie is already present. (But then, paired negative conditions tend to confuse me horribly and you may already be doing exactly that.)
Does your client operate from such a wide range of IPs that you can’t simply make a REMOTE_ADDR condition instead?
if ($_GET['foo'])
setcookie('bar', 'something_random');
$nocache = time();
echo <<<EOF
<html>
<head>
<title>Please wait...</title>
</head>
<body onLoad = "setTimeout(`window.location.href = 'https://www.original.com/?h=$nocache'`, 3000)">
Please wait...
</body>
</html>
EOF; what other mod_rewrite directives are in the .htaccess file or any server config files?
# Compress
<IfModule mod_deflate.c>
AddOutPutFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/x-javascript text/xml application/xml application/xml+rss application/vnd.ms-fontobject application/x-font-ttf
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
There's nothing else in the .htaccess. I didn't think to look at the server config files, but I THINK they should be OK.And it shouldn’t make a difference, because unless you set RewriteOptions to Inherit (or one of its many 2.4 variants), as soon as you hit htaccess, all previous RewriteRules should be as if they never existed.
I tried to copy them to the post but I'm getting a Forbidden error,Yup, I’ve had that happen. I think the site code scans the post for malign content, but has no way of excluding stuff that’s inside [code] tags.
RewriteCond %{HTTP_USER_AGENT} (Android|iPhone|iPod)
RewriteCond %{HTTP_COOKIE} !phonegame
RewriteCond %{HTTP_REFERER} !phone\.html
RewriteRule ^games/(tower|palace|canal|color)/?$ https://www.example.com/games/phone.html [R=302,CO=phonegame:1:.example.com:525600,L]
(In my case, the referer acts as a kind of double markedness: If the user for some reason doesn’t do cookies, they can still get to all pages, they just have to detour via phone.html.) # if (foo === 'random_code')
RewriteCond %{QUERY_STRING} foo=random_code
RewriteRule ^ https://www.original.com/?h=%{TIME} [CO=foo:random_code:.original.com,L,R=302]
# else
RewriteCond %{HTTP_COOKIE} !foo=random_code
RewriteCond %{REQUEST_URI} !^/(images|styles\.css|javascript\.js)
RewriteRule ^ https://www.example.com [L,R=302] # if (foo === 'random_code')
RewriteCond %{QUERY_STRING} foo=random_code
RewriteRule ^ https://www.original.com/?h=%{TIME} [E=foo:%1,CO=foo:%1:.original.com,L,R=302]
# else
RewriteCond %{HTTP_COOKIE} !foo=%{ENV:foo}
RewriteCond %{REQUEST_URI} !^/(images|styles\.css|javascript\.js)
RewriteRule ^ https://www.example.com [L,R=302]