Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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>

share|improve this question

1 Answer 1

Use redirect 301, not mod_rewrite.

Examples via googlefu: http://www.webweaver.nu/html-tips/web-redirection.shtml

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

 
discard

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.