将.htaccess转换为web.config

时间:2014-12-05 05:08:06

标签: asp.net apache .htaccess iis web-config

我目前正处于从forles plesk for centos迁移到parallels plesk for windows的过程中。我遇到的唯一障碍是我意识到.htaccess将不再起作用。 这是我的.htaccess:

options -indexes +FollowSymLinks
RewriteEngine on 


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^(verify)/(.*)/([a-zA-Z0-9_-]+)$ validate_account.php?usr=$3&hash=$4 [QSA,L]
RewriteRule ^(post)/([a-zA-Z0-9_-]+)$ news.php?post=$2 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^uploads/avatars/(.+)$ ../uploads/avatars/$1 [L,NC]

Redirect 301 /signup /register

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

errordocument 404 /404.php
errordocument 403 /404.php
errordocument 500 /404.php

allow from all
#deny from all
#allow from 98.115.168.25
deny from 162.144.91.203 #attempted brute force
deny from 74.208.100.64 #attempted brute force
deny from 185.57.82.25 #tried to ddos

这是我用网站生成的web.config:

<rule name="rule 1F">
    <match url="^(.*)$"  />
    <action type="Rewrite" url="/{R:1}.php"  />
</rule>
<rule name="rule 2F" stopProcessing="true">
    <match url="^(verify)/(.*)/([a-zA-Z0-9_-]+)$"  />
    <action type="Rewrite" url="/validate_account.php?usr={R:3}&amp;hash={R:4}"  appendQueryString="true" />
</rule>
<rule name="rule 3F" stopProcessing="true">
    <match url="^(post)/([a-zA-Z0-9_-]+)$"  ignoreCase="true" />
    <action type="Rewrite" url="/news.php?post={R:2}"  appendQueryString="true" />
</rule>
<rule name="rule 4F" stopProcessing="true">
    <match url="^uploads/avatars/(.+)$"  ignoreCase="true" />
    <action type="Rewrite" url="/../uploads/avatars/{R:1}"  />
</rule>
<rule name="rule 5F">
    <match url="(.*)"  />
    <action type="Rewrite" url="/https://%{HTTP_HOST}%{REQUEST_URI}"  />
</rule>
<rule name="rule 6F" stopProcessing="true">
    <match url="^"  />
    <action type="Rewrite" url="/http://%1%{REQUEST_URI}"  />
</rule>

每当我尝试访问该网站时,它都会给我500个内部服务器错误,我们将不胜感激。

2 个答案:

答案 0 :(得分:0)

试试这个并告诉我

<rule name="rule 1X">
        <match url="^(.*)$"  />
        <action type="Rewrite" url="/{R:1}.php"  />
    </rule>
    <rule name="rule 2X" stopProcessing="true">
        <match url="^(verify)/(.*)/([a-zA-Z0-9_-]+)$"  />
        <action type="Rewrite" url="/validate_account.php?usr={R:3}&amp;hash={R:4}"  appendQueryString="true" />
    </rule>
    <rule name="rule 3X" stopProcessing="true">
        <match url="^(post)/([a-zA-Z0-9_-]+)$"  ignoreCase="true" />
        <action type="Rewrite" url="/news.php?post={R:2}"  appendQueryString="true" />
    </rule>
    <rule name="rule 4X" stopProcessing="true">
        <match url="^uploads/avatars/(.+)$"  ignoreCase="true" />
        <action type="Rewrite" url="/../uploads/avatars/{R:1}"  />
    </rule>
    <rule name="rule 5X">
        <match url="(.*)"  />
        <action type="Rewrite" url="/https://%{HTTP_HOST}%{REQUEST_URI}"  />
    </rule>
    <rule name="rule 6X" stopProcessing="true">
        <match url="^"  />
        <action type="Rewrite" url="/http://%1%{REQUEST_URI}"  />
    </rule>

答案 1 :(得分:0)

安装ISAPI Rewrite的免费版本后,我可以在IIS 7中使用.htaccess。