整合:Drupal:安装:URL Rewrite

来自站长百科
跳转至: 导航、​ 搜索

Pages that need review by other documentation team members.Sections which need expansion (i.e. more detail, clarification, etc...)

简洁的URL/重写模块使得如Apache这样的web服务器能够重写Gallery URL请求,如将http://www.site1.com/?q=gallery&g2_itemId=24重写为人可读性更高的格式http://www.site1.com/gallery/album/image.jpg.html

在大多数单个站点中,在Gallery模块中配置简洁URL支持是很直白的。然而,非典型的服务器和站点配置会在启用简洁URL时遇到困难。

单个站点的配置[ ]

  1. 配置独立Gallery中的重写模块
  2. 启用Drupal中的简洁URL
  3. 临时允许Drupal的htaccess文件可写
    chmod 666 /path/to/drupal/.htaccess
  4. 在Drupal的管理区域,选择Site Configuration>Gallery Settings
  5. 选择安装标签Install
  6. 扩展第四步:简洁URLs / URL重写设定
  7. 确认或更正你的Drupal文件路径及URL
  8. 点击Test htaccess按钮

成功的话会看到'OK'状态.

多站点配置[ ]

多站点环境下的简洁URL配置需要更多的工作。一般来说,最好的手段包括配置单个站点的简洁URL,备份Drupal的htacces文件并为各后续网站照葫芦画瓢地应用重写规则。

如果各Gallery站点的Mod Rewrite规则相同的话,就为各额外站点复制并粘贴首选规则集并分别进行路径的编辑。

Gallery模块重写股则区块出现在Drupal的重写规则之上。以下为一个示例区块:

 # 开始Url Rewrite部分
 # (自动生成,请勿编辑此部分)
 <IfModule mod_rewrite.c>
   Options +FollowSymlinks
   RewriteEngine On
   
   RewriteBase /
   
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -d [OR]
   RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   -   [L]
   
   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site1.com/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3   [QSA,L]
   RewriteCond %{THE_REQUEST} /gallery/([^?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /index.php?q=gallery&g2_path=%1   [QSA,L]
 </IfModule>

你需要复制以添加另一网站的部分为:

   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site1.com/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3   [QSA,L]
   RewriteCond %{THE_REQUEST} /gallery/([^?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /index.php?q=gallery&g2_path=%1   [QSA,L]

复制此区块,将其粘贴到之前部分之下并编辑DownloadItem 行中的url。最后gallery.module重写区块应为如下的样子:

 # 开始Url Rewrite部分
 # (自动生成,请勿编辑此部分)

<IfModule mod_rewrite.c>

   Options +FollowSymlinks
   RewriteEngine On
   
   RewriteBase /
   
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -d [OR]
   RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   -   [L]
   
   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site1.com/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3   [QSA,L]
   RewriteCond %{THE_REQUEST} /gallery/([^?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /index.php?q=gallery&g2_path=%1   [QSA,L]
   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site2.com/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3   [QSA,L]
   RewriteCond %{THE_REQUEST} /gallery/([^?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /index.php?q=gallery&g2_path=%1   [QSA,L]
 </IfModule>

疑难解答[ ]

Support for this feature relies on the availability of Apache's mod_rewrite module. It is impossible to enable clean URLs without it. Check with your web hosting provider if you're unsure whether mod_rewrite is enabled.

Installing Gallery 2 in a folder named 'gallery' within your Drupal directory will create rewrite conflicts and make enabling clean URLs impossible. Disable the URL Rewrite moduel in Gallery, rename the Gallery 2 folder to anything but 'gallery', re-enalbe Gallery's Rewrite Module, and try again.

If you experience an error like this when navigating to Drupals gallery settings pages;

Error (ERROR_MISSING_OBJECT) : Parent 7 path install

尝试将此行;

  RewriteCond %{THE_REQUEST} /gallery/([^?]+)(\?.|\ .)

修改为;

  RewriteCond %{THE_REQUEST} \ /gallery/([^?]+)(\?.|\ .)