EEDU Blog: 博客 ·  资讯 ·  论坛 ·  留言
登录 新用户? 注册   |  

ahaoxie's blog

订阅博客:

环境生态网站长

阅读全文

Drupal 在 IIS7 上的简洁链接配置

Windows 主机使用 IIS7 作为 Web 服务器,并安装有 URL Rewrite 组件,可以实现 Drupal 的简洁链接(Clean URLs)。

首先把 Drupal 的文件解压到主机中,如果不是根文件夹,为避免出错,推荐修改 Drupal 的站点配置文件「/drupaldir/sites/defualt/settings.php」中的「$base_url」一项的值为网站首页的 URL,例如:

$base_url = 'http://abc.com;

然后修改 web.config 文件,如果不存在则新建一个,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <!-- Don't show directory listings for  URLs which map to a directory. -->
 <directoryBrowse  enabled="false" />

 <!--
 Caching configuration  was not delegated by default. Some hosters may not delegate the caching
 configuration to site owners by default and that may cause errors when  users install. Uncomment
 this if you want to and are allowed  to enable caching
 -->
 <!--
 <caching>
 <profiles>
 <add extension=".php"  policy="DisableCache" kernelCachePolicy="DisableCache" />
 <add extension=".html" policy="CacheForTimePeriod"  kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
 </profiles>
 </caching>
 -->

 <rewrite>
 <rules>
 <!-- rule  name="postinst-redirect" stopProcessing="true">
 <match url="." />
 <action type="Rewrite"  url="postinst.php"/>
 </rule -->

 <rule name="Protect files and directories from prying eyes"  stopProcessing="true">
 <match  url=".(engine|inc|info|install|module|profile|test|po|sh|.sql|postinst.1|theme|tpl(.php)?|xtmpl|svn-base)$|^(code-style.pl|Entries.|Repository|Root|Tag|Template|all-wcprops|entries|format)$"  />
 <action type="CustomResponse" statusCode="403"  subStatusCode="0" statusReason="Forbidden" statusDescription="Access is  forbidden." />
 </rule>
 <rule  name="Force simple error message for requests for non-existent  favicon.ico" stopProcessing="true">
 <match  url="favicon.ico" />
 <action type="CustomResponse"  statusCode="404" subStatusCode="1" statusReason="File Not Found"  statusDescription="The requested file favicon.ico was not found" />
 </rule>
 <!-- To redirect all users to  access the site WITH the 'www.' prefix,
 http://example.com/...  will be redirected to http://www.example.com/...)
 adapt and uncomment the following:   -->
 <!--
 <rule name="Redirect to add www" stopProcessing="true">
 <match url="^(.)$" ignoreCase="false" />
 <conditions>
 <add input="{HTTP_HOST}"  pattern="^example.com$" />
 </conditions>
 <action type="Redirect" redirectType="Permanent"  url="http://www.example.com/{R:1}" />
 </rule>
 -->
 <!-- To redirect all users to access the  site WITHOUT the 'www.' prefix,
 http://www.example.com/... will be redirected to http://example.com/...)
 adapt and uncomment the following:   -->
 <!--
 <rule name="Redirect to remove www" stopProcessing="true">
 <match url="^(.)$" ignoreCase="false" />
 <conditions>
 <add input="{HTTP_HOST}"  pattern="^www.example.com$" />
 </conditions>
 <action type="Redirect" redirectType="Permanent"  url="http://example.com/{R:1}" />
 </rule>
 -->
 <!-- Rewrite URLs of the form 'x' to the form  'index.php?q=x'. -->
 <rule name="Short URLS"  stopProcessing="true">
 <match url="^(.*)$"  ignoreCase="false" />
 <conditions>
 <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false"  negate="true" />
 <add input="{REQUEST_FILENAME}"  matchType="IsDirectory" ignoreCase="false" negate="true" />
 <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false"  negate="true" />
 </conditions>
 <action type="Rewrite" url="index.php?q={R:1}"  appendQueryString="true" />
 </rule>
 </rules>
 </rewrite>

 <!-- httpErrors>
 <remove statusCode="404" subStatusCode="-1" />
 <error  statusCode="404" prefixLanguageFilePath="" path="/index.php"  responseMode="ExecuteURL" />
 </httpErrors -->

 <defaultDocument>
 <!-- Set the default document -->
 <files>
 <remove value="index.php" />
 <add value="index.php" />
 </files>
 </defaultDocument>
 </system.webServer>
</configuration>

以上配置有数个功能,有兴趣的可以研读一下它自带的说明。关于更多如何使用 URL Rewrite 组件的信息可以参考微软官方的文章 Using the URL Rewrite Module

最后再修改 Drupal 的站点配置文件中的「$conf['clean_url'];」一项,将其值设置为1,如果此项不存在,在文件的最后一行增加即可:

$conf['clean_url'] = 1;
发表于: 2010-10-07 23:16 | 全文(查看: 429) | 评论(0) | 本文地址 | 收藏 
分类: 服务器应用(148)   标签: Drupal  Rewrite  新知  

"Drupal 在 IIS7 上的简洁链接配置" 的评论: (共 0 条)

你对本文的评论:

登录后再作评论
Page was generated in 15 milliseconds