title: Remove one "folder" from URL with a 301 redirect, keep both URLs working
body: <p>My site URL: <a href="http://example.com/website/pages/home" rel="nofollow">http://example.com/website/pages/home</a></p>
  
  <p>Wanted URL: <a href="http://example.com/pages/home" rel="nofollow">http://example.com/pages/home</a></p>
  
  <p>I need this to be a 301 redirect so that search engines update my links.</p>
  
  <p>This is what I got so far:</p>
  
  <pre><code>
  Options +FollowSymLinks
  Options -Indexes
  DirectoryIndex index.php index.html
  RewriteEngine on
  \# remove /website/
  RedirectMatch  ^(.+)(/website/)(.+)$ $1/$3 [L]
  \# remove index.php from URL
  RewriteCond $1 !^(index\.php^)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  \# deny access to wget user agent
  RewriteCond %{HTTP_USER_AGENT} wget [NC]
  RewriteRule (.*) /$1 [L]
  </code></pre>
  
  <p>What happens with this rules:</p>
  
  <p><strong>Inserted URL</strong>: <a href="http://example.com/website/pages/home" rel="nofollow">http://example.com/website/pages/home</a></p>
  
  <p><strong>Redirected URL</strong>: <a href="http://example.com/index.php/pages/home" rel="nofollow">http://example.com/index.php/pages/home</a></p>
  
  <p><strong>Expected results</strong>: <a href="http://example.com/pages/home" rel="nofollow">http://example.com/pages/home</a></p>
  
  <p>Thanks in advance for your help.</p>
  
  <p>**<strong>SOLVED*</strong>*</p>
  
  <pre><code>
  Options +FollowSymLinks
  Options -Indexes
  DirectoryIndex index.php index.html
  
  RewriteEngine on
  
  # remove /website/
  RedirectMatch  ^(.+)(index.php/website/)(.+)$ $1$3 [R=301,L]
  
  # remove index.php from URL
  RewriteCond $1 !^(index\.php^)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  
  # deny access to wget user agent
  RewriteCond %{HTTP_USER_AGENT} wget [NC]
  RewriteRule (.*) /$1 [L]
  
  </code></pre>