Note that there are some explanatory texts on larger screens.

plurals
  1. PO.htaccess rewrite to simultaneously change domain and remove path
    text
    copied!<p>My URL structure is currently as follows:</p> <p><a href="http://domain.com/folder/filename" rel="nofollow">http://domain.com/folder/filename</a> (CURRENT)</p> <p>I want to change this so that I can use the following URL instead:</p> <p><a href="http://sub.domain.com/filename" rel="nofollow">http://sub.domain.com/filename</a> (NEW)</p> <p>So accessing the CURRENT <strong>or</strong> the NEW url, should load the file located at the CURRENT url, but show the NEW url in the address bar. It should only apply to the "/folder/" path.</p> <p>sub.domain.com is a mirror of domain.com, ie. they share the same file system and root directory.</p> <p>This is what I have so far:</p> <pre><code>Options +FollowSymLinks RewriteBase / RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC] RewriteCond %{REQUEST_URI} ^/folder/?(.*)$ [NC] RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L] </code></pre> <p>This is working, but is missing the rule to remove the "/folder/" from the path. I've tried combining multiple RewriteRule's with no luck. Any ideas? Thanks.</p> <hr> <p><strong>UPDATE:</strong> Thanks again @Gerben - I understand what your rules are doing now, but the second one isn't working for me. I suspect because it's conflicting with some other rewrite rules, in particular those of WordPress, which are lower down in my .htaccess file:</p> <pre><code># BEGIN WordPress RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress </code></pre> <p>Because of this the page ends up in a redirect loop, ie (from Chrome): "The webpage at <a href="http://sub.domain.com/folder/index.php" rel="nofollow">http://sub.domain.com/folder/index.php</a> has resulted in too many redirects." - while the url I was originally trying to access was, for example, <a href="http://sub.domain.com/page" rel="nofollow">http://sub.domain.com/page</a></p> <p>Any ideas?</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