Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirecting visitors correctly (PHP and Regex)
    text
    copied!<p>I want if my visitors go to <code>subdomain.example.com</code> that they get redirected to <code>anothersubdomain.example.com</code>. And if they go to <code>css.subdomain.example.com</code> that they get redirected to <code>css.anothersubdomain.example.com</code> etc.</p> <p>I've tried the following regexes (with preg_match):</p> <p><strong>Attempt 1:</strong></p> <pre><code>if(preg_match('#(([\w\.-]+)\.subdomain|subdomain)\.example\.com#', $_SERVER['SERVER_NAME'], $match)) { header('Location: http://'.$match[1].'anothersubdomain.example.com/'); } </code></pre> <p>If they go to: <code>subdomain.example.com</code> they get redirected to: <code>anothersubdomain.example.com</code></p> <p>But If they go to: <code>css.subdomain.example.com</code> they get redirected also to: <code>subdomain.example.com</code> - So that is not working</p> <p><strong>Attempt 2:</strong></p> <pre><code>if(preg_match('#([\w\.-]+)\.subdomain\.example\.com#', $_SERVER['SERVER_NAME'], $match)) { header('Location: http://'.$match[1].'.anothersubdomain.example.com/'); } </code></pre> <p>If they go to: <code>css.subdomain.example.com</code> they get redirected to: <code>css.anothersubdomain.example.com</code></p> <p>But If they go to: <code>subdomain.example.com</code> they get redirected to: <code>.subdomain.example.com</code> - And that URL is not valid so also this attempt is not working.</p> <p>Somebody has an answer? I want not to use nginx or apache rewrites.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload