URL重写子根,禁止访问的子文件夹 [英] Url rewrite subfolder to root and forbid accessing subfolder
问题描述
我已经Drupal的安装在一个子文件夹中的的Drupal ,但我想访问的页面,因为它是在根文件夹: http://www.example.com 代替 http://www.example.com/drupal
我能有这个工作,但它也有网址的工作包含子文件夹,所以我的 http://www.example.com 并克隆网站的 HTTP: //www.example.com/drupal
什么是规则禁止访问的子文件夹?
我希望所有的url开头的 http://www.example.com/drupal 被禁止的。
这是的.htaccess 在/目录下:
选项-Indexes
选项+的FollowSymLinks
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)$ [NC]
重写规则^的http://%1%{REQUEST_URI} [L,R = 301]
重写规则^(。* +)$的Drupal / $ 1 [L,QSA]
< / IfModule>
这是Drupal的的.htaccess 在/ Drupal的/目录:
选项-Indexes
选项+的FollowSymLinks
的ErrorDocument 404的index.php
DirectoryIndex的index.php文件的index.html index.htm的
#不能在运行时改变覆盖PHP的设置。看到
在#网站/默认/ default.settings.php和drupal_initialize_variables()
#包括/ bootstrap.inc文件的,可以在运行时改变设置。
#PHP 5中,阿帕奇1和2。
< IfModule mod_php5.c>
的php_flag magic_quotes_gpc的关
的php_flag magic_quotes_sybase关闭
的php_flag register_globals的关闭
的php_flag session.auto_start关闭
php_value合格的mbstring.http_input
php_value的mbstring.http_output通
的php_flag关闭的mbstring.encoding_translation
< / IfModule>
#要求mod_expires被激活。
< IfModule mod_expires.c>
#开启到期。
ExpiresActive在
#缓存的访问后,所有文件2周(A)。
ExpiresDefault A1209600
< FilesMatch \ .PHP $>
#不要让PHP脚本被缓存,除非他们明确地发送缓存
#头自己。否则,所有的脚本必须覆盖
#头通过mod_expires设置,如果他们想要另一个缓存行为。这可能
#如果早发生在引导过程中的错误而失败,并可能会导致
#问题,如果一个非Drupal的PHP文件被安装在一个子目录中。
ExpiresActive关闭
< / FilesMatch>
< / IfModule>
#各个重写规则。
< IfModule mod_rewrite.c>
RewriteEngine叙述上
#阻止访问隐藏,其名称以期目录。本
#包括使用版本控制系统,如颠覆或目录
#Git的存储控制文件。文件名称开头一段,以及
#所使用的CVS控制文件,由FilesMatch指令保护
# 以上。
重写规则(^ | /)\。 - [F]
#重定向所有用户访问该网站的WWW。 preFIX,
#(HTTP://example.com / ...将被重定向到http://www.example.com / ...)
#取消以下:
#的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
#重写规则^的http://www.% {HTTP_HOST}%{REQUEST_URI} [L,R = 301]
#
#重定向所有用户访问该网站没有WWW。 preFIX,
#(HTTP://www.example.com / ...将被重定向到http://example.com / ...)
#取消以下:
的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)$ [NC]
重写规则^的http://%1%{REQUEST_URI} [L,R = 301]
的RewriteBase / Drupal的
#将所有请求传递不直接引用文件中的文件系统
#index.php文件。清洁网址在drupal_environment_initialize处理()。
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!= /的favicon.ico
#RewriteRule ^的index.php [L]
重写规则^(。*)$的index.php?Q = $ 1 [L,QSA]
#规则正确地服务于gzip的COM pressed CSS和JS文件。
#需要启用mod_rewrite的双方和mod_headers中。
< IfModule mod_headers.c>
#如果存在的话,客户接受GZIP即成gzip的COM pressed CSS文件。
的RewriteCond%{HTTP:接受编码} GZIP
的RewriteCond%{REQUEST_FILENAME} \。GZ -s
重写规则^(。*)\。CSS $ 1 \的.css \ .gz的[QSA]
#即成gzip的COM pressed JS文件,如果存在的话,客户接受GZIP。
的RewriteCond%{HTTP:接受编码} GZIP
的RewriteCond%{REQUEST_FILENAME} \。GZ -s
重写规则^(。*)\。JS $ 1 \ .js文件\ .gz的[QSA]
#即成正确的内容类型和prevent mod_deflate模块双GZIP。
重写规则\的.css \ .gz的$ - [T =文本/ CSS,E =无gzip压缩:1]
重写规则\ .js文件\ .gz的$ - [T =文/ javascript中,E =无gzip压缩:1]
< FilesMatch(\ .js文件\。广州| \的.css \。广州)$>
#即成正确的编码类型。
头追加内容编码的gzip
#强制代理来高速缓存gzip压缩和放大器;另外非gzip压缩的CSS / JS文件。
头追加因人而异接受编码
< / FilesMatch>
< / IfModule>
< / IfModule>
我解决了这个在在加入后 RewriteEngine叙述这两行
/ Drupal的/的.htaccess
:
#拒绝访问的URL开始/ Drupal的/
的RewriteCond%{THE_REQUEST} ^([AZ] {3,9})\ / Drupal的/
重写规则。* - [F,L]
使用的 R = 403 避免问题的Drupal未找到的处理程序:的ErrorDocument 404的Drupal / index.php文件
I have drupal installed in a subfolder drupal, but I want to access pages as it is in root folder: http://www.example.com instead of http://www.example.com/drupal
I'm able to have this working, but it's also working with url containing subfolder, so I have http://www.example.com and a clone site in http://www.example.com/drupal
What is the rule to forbid access to subfolder?
I want all url starting with http://www.example.com/drupal being forbidden.
This is .htaccess in / directory:
Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*+)$ drupal/$1 [L,QSA]
</IfModule>
And this is drupal .htaccess in /drupal/ directory:
Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 index.php
DirectoryIndex index.php index.html index.htm
# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_initialize_variables() in
# includes/bootstrap.inc for settings that can be changed at runtime.
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
</FilesMatch>
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or
# Git to store control files. Files whose names begin with a period, as well
# as the control files used by CVS, are protected by the FilesMatch directive
# above.
RewriteRule "(^|/)\." - [F]
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteBase /drupal
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
#RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# 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>
</IfModule>
</IfModule>
I solved this adding these two lines after RewriteEngine on
in /drupal/.htaccess
:
# deny access to url starting with /drupal/
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ /drupal/
RewriteRule .* - [F,L]
Using R=403 avoids problems with drupal "not found" handler: ErrorDocument 404 drupal/index.php
这篇关于URL重写子根,禁止访问的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!