Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a website reached from this url:

being served from this directory:


In public_html I have this .htaccess

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

Which lets me get to the site like this:

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

for example:
is redirected to...

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 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

share|improve this question

Use redirect 301, not mod_rewrite.

Examples via googlefu:

Edit: or R=301 in your rewrite flags.

share|improve this answer
Would a redirect work? I still want the user to get to the correct page - just strip out the folder. – Sam Feb 9 '11 at 0:57
In your case, the redirect rewrite will need to go in a .htaccess file that's located in your /cms folder (as opposed to the one you have here in your root public directory), since htaccess works on a per-directory basis. – godheadatomic Feb 10 '11 at 19:47
It would be simple, too -- so your /cms/.httaccess would probably look something like.. RewriteEngine On, RewriteBase /, RewriteRule (.*) %1 [R=301] ... I think that should work. Ooh, but now I'm wondering if that may mess with Drupal's internal links. It's worth a shot. – godheadatomic Feb 10 '11 at 20:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.