几个子文件夹

问题描述:

我有一些麻烦与我的脚本的.htaccess例外..几个子文件夹

,当我访问http://www.domain.com/this-is-a-topic我希望它重定向到http://www.domain.com/index.php?t=this-is-a-topic ...但是当它说:“管理”,“网站地图”或一些其他的事情,我希望它看起来要么另一个改写状态或只是简单地让http://www.domain.com/administration/

这里是我的代码:

RewriteCond %{REQUEST_URI} !(administration|sitemap)/(.*)\. [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 


# Dync links 

RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L] 
RewriteRule ^lang:([0-9]+)?$     index.php?l=$1 [L] 


RewriteRule ^sitemap/?$       index.php?sitemap=sitemap [L] 

RewriteRule ^error/([0-9]+)?$     index.php?error=$1 
RewriteRule ^([a-zA-Z0-9-]+)/?$    index.php?t=$1 

的问题是,当我写/管理/它去http://www.domain.com/index.php?t=/administration/而不是去http://www.domain.com/administration/index.php

这里有两个问题。首先,你的条件

RewriteCond %{REQUEST_URI} !(administration|sitemap)/(.*)\. [NC] 

将永远是真实的,因为%{REQUEST_URI}价值始终拥有领先的正斜杠(这样的格局将永远不匹配)。对于直接浏览到站点地图和管理文件夹的情况,您也可能不想查找该点。

其次,条件仅适用于第二天规则,因此当文件夹会为规则

RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L] 

,他们不会为

RewriteRule ^([a-zA-Z0-9-]+)/?$     index.php?t=$1 

被忽略被忽略有几种方法解决这个问题,但最容易的可能是忽略规则的其余部分,在这种情况下,您的任何条件与前期匹配,如下所示:

# Don't rewrite and stop processing if any of the following is true 
RewriteCond %{REQUEST_URI} ^/(administration|sitemap)/ [NC,OR] 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 

# Dync links 
RewriteRule ^([a-zA-Z0-9-]+)/lang:([0-9]+)?$ index.php?t=$1&l=$2 [L] 
RewriteRule ^lang:([0-9]+)?$     index.php?l=$1 [L] 

RewriteRule ^sitemap/?$       index.php?sitemap=sitemap [L] 

RewriteRule ^error/([0-9]+)?$     index.php?error=$1 
RewriteRule ^([a-zA-Z0-9-]+)/?$     index.php?t=$1 
+0

它不起作用 - 它仍然重定向到404错误页面:/ – 2010-10-03 20:30:42

+0

或更准确地说 - 它重定向到使用php-headers创建的“error/404 /”!这意味着,如果所需的文件夹/文件不存在,它将重定向到错误/ 404/:) – 2010-10-03 20:35:30

+0

@Dennis Lauritzen:嗯......好吧,我会把它放在我的测试服务器上看看可能会出现什么问题。 – 2010-10-03 20:49:32