2011-08-19 46 views
0

我正在尝试设置一个重写,它将获取新闻文件夹中的任何页面(除ind​​ex.shtml和template.shtml(其中template.shtml将在其中获取变量消息) 。它)其他所有的页面应该重写template.shtml新闻=(名称相同新闻/名)Apache Rewrite Directory with Exceptions

我至今是:?

RewriteCond %{REQUEST_URI} !^/news/((index|template).shtml)?$ 
RewriteRule ^news/(.*) /news/template.shtml?news=$1 

这似乎排除了主/新闻/,但不是template.shtml,并且重写似乎循环。

我该如何解决这个问题? Ÿ帮助将不胜感激。

谢谢。

回答

1

好 - 这一个工程对我蛮好:

RewriteCond %{REQUEST_URI} !^/news/(index|template)\.shtml$ 
RewriteRule ^news/(.+)$ /news/template.shtml?news=$1 [L,QSA] 
  1. 此规则将忽略请求/news/index.shtml/news/template.shtml

  2. 它只会请求/news/(因为我已将.*更改为.+以确保安全)。

  3. 任何东西都不会被改写为/news/template.shtml?news=whatever

  4. 我还添加了QSA标志来保留所有现有的查询字符串(保持转诊有用的数据,如/news/hello-pink-kitten?source=google将被改写为/news/template.shtml?news=hello-pink-kitten&source=google

+0

谢谢,但似乎没有工作。也许是因为我把它放在另一个目录中?试过: – fanfavorite

+0

忽略最后一条消息,这是因为template.shtml与查询字符串不会被省略。试图找出解决方案。 – fanfavorite

+0

再次无视。 template.shtml脚本在导致重写循环的目录内拉入另一页。谢谢。 – fanfavorite