从包含网站的文件夹重定向

从包含网站的文件夹重定向

我通过这个网址访问了一个网站:

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

从该目录提供服务:

public_html/cms/index.php

在 public_html 中我有这个 .htaccess

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

这让我可以像这样访问该网站:

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

但是现在如果我引用“旧”地址,我想使用永久重定向代码重定向到重写的地址。

例如:

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

我怎样才能实现这一点?

编辑:Drupal(cms) 附带的 .htaccess 文件中也写了此内容。我尝试启用它,但似乎没有任何效果。

  # 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

编辑:包括更多我的.htaccess 文件-似乎相关。

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

答案1

使用重定向 301,而不是 mod_rewrite。

来自 googlefu 的示例: http://www.webweaver.nu/html-tips/web-redirection.shtml

编辑:或重写标志中的 R=301。

相关内容