2013-12-17 69 views
0

您好:我需要幫助將我的IIS重寫規則轉換爲.htaccess文件。 我對服務器規則不是很熟悉(我主要是設計和開發網站)。 我需要一些幫助。我目前正在將一個網站(dolyn.com)從另一個服務器移到我們的網站,他們最初使用WIMP設置啓動它,因此使用來自IIS(web.config)的URL重寫而不是來自Apache(.htacces)的mod_rewrite模塊[我真的不太清楚它的物流 - 我剛剛被要求確保它在我們的服務器上運行。這裏是原來的web.config文件:將web.config轉換爲.htaccess

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 

    <!-- Doesn't work on DEV servers, uncomment it on live site --> 
    <!-- httpErrors errorMode="Detailed" /--> 

     <rewrite> 
      <rules> 
       <clear /> 

       <!-- 
       This rule will redirect all requests to a single main domain as specified in the 1st condition, except if it's on a baytek dev site. 
       Instructions: 
        1. Enable the rule 
        2. Change "^www.maindomain.com$" to real domain, ex. "^www.bayteksystems.com$", in both places. 
       --> 

       <rule name="Redirect to WWW" stopProcessing="true" enabled="false"> 
        <match url=".*" /> 
        <conditions logicalGrouping="MatchAll"> 
         <add input="{HTTP_HOST}" pattern="^www.maindomain.com$" negate="true" /> 
         <add input="{HTTP_HOST}" pattern="dev.bayteksystems.com$" negate="true" /> 
        </conditions> 
        <action type="Redirect" url="http://www.maindomain.com/{ToLower:{R:0}}" redirectType="Permanent" /> 
       </rule> 

       <rule name="Add trailing slash" stopProcessing="true"> 
        <match url="(.*[^/])$" /> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Redirect" url="{ToLower:{R:1}}/" redirectType="Permanent" /> 
       </rule> 

       <rule name="Convert to lower case" stopProcessing="true"> 
        <match url=".*[A-Z].*" ignoreCase="false" /> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" /> 
       </rule> 

       <rule name="DynamicURLs" enabled="true" stopProcessing="true"> 
        <match url="^(.*)$" /> 
        <conditions logicalGrouping="MatchAll"> 
         <add input="{URL}" pattern="^_cms.*" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Rewrite" url="index.php?page={R:1}&amp;url_rewrite=true" /> 
       </rule> 

      </rules> 
     </rewrite> 

    </system.webServer> 
</configuration> 

我已經做了相當多的研究,它看起來像我可能還需要一個htpasswd文件?它是否正確?正如你可以從web.config服務器它來自baytechsystems.com,我們將它移動到dnsnetworks.ca

回答

0

看起來你不需要一個htpasswd文件,除非你需要認證(這可能是如此,但我看不到任何東西在你的web.comfig因此,像這樣的htaccess的文件在您的文檔根:

RewriteEngine On 

# Redirect to WWW 
RewriteCond %{HTTP_HOST} !www\.dnsnetworks\.ca$ [NC] 
RewriteCond %{HTTP_HOST} !dev\.dnsnetworks\.ca$ [NC] 
RewriteRule ^(.*)$ http://www.dnsnetworks.ca/$1 [L,R=301] 

# Add trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+[^/])$ /$1/ [L,R=301]] 

# Convert to lower case 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*[A-Z].*)$ /${tolower:$1} [L,R=301] 

# DynamicURLs 
RewriteCond %{REQUEST_URI} !^/_cms 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?page=$1&url_rewrite=true [L] 

這裏唯一的問題是「轉換爲小寫」的一部分。 tolower功能需要在您的服務器配置中定義。像這樣:

RewriteMap tolower int:tolower 

否則,該規則將導致錯誤。如果你無法訪問你的服務器/虛擬主機配置,那麼只需註釋掉該規則,因爲你不能使用mod_rewrite強制執行小寫。

+0

它看起來像它的重定向到www.dylon.com - 我想要的是它在web01.dnsnetworks.ca/dolyn(這是所有文件都是... index.php).. – user3112402

+0

當我嘗試加載網站...。這是什麼彈出到錯誤日誌中; (/_erl/share/php/index.php)//usr/share/php中的/app/website/doly/_includes/common.php錯誤:require_once():開啓所需的'/app/website/doly/_includes/common.php'第13行的app/website/dolyn/index.php 我想我錯過了服務器上的php-devel庫,因爲它試圖使用php的php-pear擴展。 它不是一個簡單的安裝,因爲我運行的是PHP的最新版本,而我的系統的開發庫尚不可用。你認爲@JonLin – user3112402

+0

@ user3112402有很多各種各樣的PHP庫,它們都沒有安裝最少的PHP,LOTS。但是你應該確保'/ app/website/doly/_includes/common.php'存在 –