Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Edit:</p> <p>I have just seen your comment about doing it only via PHP, because you can't change <code>document_root</code> While I still think using <code>.htaccess</code> would be a better solution, you could certainly do this only using PHP, here's a quick mock-up:</p> <pre><code>// Grab the URL parts $url = parse_url("http://stackoverflow.com/posts/20420420"); // Redirect the user to the same path in `sub_dir` header('Location: '. $url['scheme'] .'://'. $url['host'] .'/'. 'sub_dir'. $url['path']); </code></pre> <p>This would redirect the user to <code>http://stackoverflow.com/sub_dir/posts/20420420</code>.</p> <p>Other people have suggested using <a href="http://php.net/manual/en/function.include.php" rel="nofollow"><code>include()</code></a>, you could combine this with my <a href="http://php.net/manual/en/function.parse-url.php" rel="nofollow"><code>parse_url()</code></a> example above to dynamically call <code>include()</code> to load the file from <code>sub_dir</code>.</p> <hr> <p>I see a few ways of doing this...</p> <p>You could use PHP's <a href="http://php.net/manual/en/function.header.php" rel="nofollow"><code>header()</code></a> function, but this wouldn't really be ideal.</p> <p>You could also use <code>.htaccess</code>, something like:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine on RewriteCond %{REQUEST_URI} !^sub_dir RewriteRule ^(.*)$ sub_dir/$1 [L] &lt;/IfModule&gt; </code></pre> <p>If you placed this in <code>public_html</code> requests would be passed to <code>sub_dir</code>. So if you requested <code>example.com/test.php</code> you would actually be loading <code>example.com/sub_dir/test.php</code>.</p> <p>What's your hosting setup like? Depending on your environment you can also change your webservers <code>document_root</code>...</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