2013-10-21 125 views
2

在我的服务器上我有多个域。mod_rewrite不隐藏子目录

RewriteEngine On 
RewriteBase/

# 1. Redirect multiple domains to http://domain.de/ 
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.de [NC] 
RewriteRule ^/?(.*) http://domain.de/$1 [L,R,NE] 

# 2. Redirect all requests to /subdirectory 
RewriteRule ^$ /subdirectory [L] 

的2.规则工作正常,但它并不隐藏子目录中的网址,也没有按预期工作:为http://domain.de/content/image.png返回404的请求,因为实际的文件位于http://domain.de/subdirectory/content/image.png

此外,我有一些工具位于子目录/subdirectory旁边的工具文件夹。我想确保我仍然可以访问它们。这目前正在工作。

问题

我怎样才能确保,对于http://domain.de/content/image.png作品的要求?

我试过

RewriteCond %{REQUEST_URI} !^/subdirectory/ 
RewriteRule (.*) /subdirectory/$1 [L] 

但是,这只是返回错误500在Apache的错误日志中的条目:`请求超过了10个内部重定向的上限,由于可能的配置错误。

编辑

由拉维Thapliyal提供的指导后,有(我猜)一件事剩余:删除URL中的子目录。

[[email protected] html]$ curl -I domain.de/ 
HTTP/1.1 301 Moved Permanently 
Date: Mon, 21 Oct 2013 12:42:22 GMT 
Server: Apache/2.2.22 (Ubuntu) 
Location: http://domain.de/subdirectory/index.php 
Vary: Accept-Encoding 
Content-Type: text/html 

这是获取返回什么,但其实我是想获得HTML不是一个位置,然后头当然会被重定向我内外兼修的子目录,然后将其对用户可见。可能与某个子目录中的另一个.htaccess文件有关?

EDIT2

看来问题是关系到subdirectory背后的TYPO3安装。接受的答案按预期工作。

回答

2

你的第一条应该做一个外部重定向(更改域在内部也不会在所有问题)

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.de [NC] 
RewriteRule ^/?(.*)$ http://domain.de/$1 [R=301,L,NE] 

不需要你的第二个规则。新规则也会覆盖根目录/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d [OR] 
RewriteCond %{REQUEST_URI} ^/?$ 
RewriteCond %{REQUEST_URI} !^/subdirectory [NC] 
RewriteRule ^(.*)$ /subdirectory/$1 [L] 

两个RewriteCond S于%{REQUEST_FILENAME}将确保您可以访问任何文件-f或目录-d外部存在/subdirectory


基本上,如果URL路径指向任何现有目录,条件 %{REQUEST_FILENAME} !-d将阻止重定向。这可以防止像 /existing-directory这样的URL重定向到 /subdirectory/existing-directory

但是,这也可能阻止根URL /请求这就是为什么你收到目录索引禁止错误。因此,上述条件是[OR]'d与%{REQUEST_URI} ^/?$以允许/也被重定向到/subdirectory

+0

访问域时将导致403。德。错误日志说:'由Options指令禁止的目录索引:/ var/www /' –

+0

为'^/$'添加一个'RewriteCond'。 –

+0

这留下了剩余的一件事:URL中的可见子目录。 –