Redirect from folder containing website

Posted by Sam on Server Fault See other posts from Server Fault or by Sam
Published on 2011-02-08T18:22:32Z Indexed on 2011/02/08 23:27 UTC
Read the original article Hit count: 227

I have a website reached from this url:

http://www.mysite.com/cms/index.php

being served from this directory:

public_html/cms/index.php

In public_html I have this .htaccess

RewriteRule (.*) cms/$1 [L]

Which lets me get to the site like this:

http://www.mysite.com/index.php

But now if I reference the 'old' address, I'd like to redirect to the rewritten address with a permanent redirect code.

for example:

http://www.mysite.com/cms/?q=node/1
is redirected to...
http://www.mysite.com/?q=node/1

How can I make this happen?

EDIT: Also in the .htaccess file supplied with Drupal(cms), this is written. I've tried enabling it, but it doesn't seem to have any effect.

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal

EDIT: Including more of my .htaccess file - seems relevant.

  # Block access to "hidden" directories whose names begin with a period. 
  RewriteRule "(^|/)\." - [F]


  #Strip cms folder from url
  RewriteRule (.*) cms/$1 


  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

  # Rules to correctly serve gzip compressed CSS and JS files.
  # Requires both mod_rewrite and mod_headers to be enabled.
  <IfModule mod_headers.c>
  # Serve gzip compressed CSS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

  # Serve gzip compressed JS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

  # Serve correct content types, and prevent mod_deflate double gzip.
  RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
  RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

  <FilesMatch "(\.js\.gz|\.css\.gz)$">
  # Serve correct encoding type.
  Header append Content-Encoding gzip
  # Force proxies to cache gzipped & non-gzipped css/js files separately.
  Header append Vary Accept-Encoding
</FilesMatch>

© Server Fault or respective owner

Related posts about apache

Related posts about mod-rewrite