1

我目前有一个安装了 Drupal 的站点,并且它具有干净的 url,因此 .htaccess 文件包含以下内容:

RewriteRule ^ index.php [L]

除此之外,我希望能够发布静态 html 页面并让它们也使用干净的 url。我正在考虑通过添加特定关键字(例如内容)将它们与drupal页面区分开来,并且可能有类似下面的内容(不确定这是否可行) - 我得到一个像www.domainname.com/nice-holiday这样的网址并翻译它到 domainname.com/ftp/pages/nice-holiday.html

RewriteRule   ^content/(.+)$   domainname.com/ftp/pages/$1.html   [L]

问题是第一条规则将尝试针对所有请求执行。我尝试将更具体的规则放在更一般的规则之前,但它仍然不起作用。你怎么能有两个基于条件的mod重写规则?例如,某个特定词的存在?更一般地说,有没有人有在一个网站上处理 CMS 和静态页面的经验 - 或者这是自找麻烦?

4

1 回答 1

0

This is where RewriteCond comes in handy.

# make sure no rewriting is done for requests without www
RewriteCond %{HTTP_HOST} !^domainname\.com
RewriteCond %{REQUEST_URI} !^/?content/
RewriteRule ^ index.php [L]

# later on...
# don't want this rule to apply for non-www requests either
RewriteCond %{HTTP_HOST} !^domainname\.com
RewriteRule ^/?content/(.+)$ http://domainname.com/ftp/pages/$1.html [L]

I think this is what you're going for? You can eliminate the %{HTTP_HOST} conditions completely if you don't actually care about the www thing. The two rules can still coexist as long as you keep the %{REQUEST_URI} condition on the drupal rewrite, so drupal rewrites explicitly do not apply for URIs beginning with the /content/ prefix.

于 2012-10-08T00:27:31.470 回答