将mod_rewrite与多个Drupal安装一起使用

时间:2011-05-17 18:13:27

标签: mod-rewrite

我在子文件夹 / drupal 中安装了Drupal的网站。此实例需要处理该站点的所有URL,并使用以下规则成功完成:

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^131.216.164.200:10011$ [NC]
RewriteRule .* http://131.216.164.200:10011/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]

RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]

但是,我现在需要添加另一个Drupal文件夹 / otherdrupal ,它将处理以 / something1 仅网址> / something2 。我试过的是修改规则:

RewriteCond %{HTTP_HOST} !^131.216.164.200:10011$ [NC]
RewriteRule .* http://131.216.164.200:10011/ [L,R=301]
RewriteRule ^(something1|something2)$ otherdrupal/index.php [L]
RewriteRule ^$ drupal/index.php [L]

RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]

RewriteCond %{DOCUMENT_ROOT}/otherdrupal%{REQUEST_URI} -f
RewriteRule .* otherdrupal/$0 [L]

但是mod_rewrite不会那么容易......

(PS我知道Drupal的多站点功能,但是假设第二个Drupal实例可能是任何以与Drupal相同的方式处理URL的Web应用程序,例如使用q URL参数。)

1 个答案:

答案 0 :(得分:0)

我明白了。我工作的.htaccess文件:

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^131.216.164.200:10011$ [NC]
RewriteRule .* http://131.216.164.200:10011/ [L,R=301]

RewriteRule ^$ drupal/index.php [L]

RewriteCond %{REQUEST_URI} ^(/something1|/something2)
RewriteRule .* otherdrupal/index.php?r=$1 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]