转换的web.config为.htaccess [英] convert web.config to .htaccess

查看:193
本文介绍了转换的web.config为.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:我需要帮助,将我的IIS重写规则.htaccess文件。 我不是很有经验的服务器规则(我主要是设计和开发的网站)。 我需要一些帮助。我从另一台服务器上的网站(dolyn.com)目前移动交给我们的,他们当初推出它使用的是WIMP的设置,因此使用的URL重写从IIS(web.config中),而不是来自Apache(.htacces)mod_rewrite的模块[我真的不完全得到它的物流 - 我刚刚被要求,以确保它的工作原理我们的服务器上。这里是原来的web.config文件:

Hello: I need help converting my IIS rewrite rules to an .htaccess file. I'm not very experienced with server rules (I mostly design and develop websites). I need some assistance. I am currently moving over a website (dolyn.com) from another server to ours and they originally launched it using a WIMP setup therefore used the URL Rewrite from IIS (web.config) rather than the mod_rewrite module from Apache (.htacces) [I really don't quite get the logistics of it - I've just been asked to make sure it works on our server. Here's the original web.config file:

<?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

I've been doing quite a bit research and it looks like I may also need an .htpasswd file? Is this correct? As you can from the web.config the server its coming from is baytechsystems.com and we're moving it to dnsnetworks.ca

推荐答案

看起来不像你需要一个htpasswd的文件,除非你需要身份验证(这也许是事实,但我没有看到你web.comfig什么所以像这样的htaccess的文件在你的文档根目录:

Doesn't look like you need an htpasswd file unless you need authentication (which may be the case, but I don't see anything in your web.comfig. So something like this in the htaccess file in your document root:

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 功能需要在服务器配置中定义。像这样的:

The only problem here is the "Convert to lower case" part. The tolower function needs to be defined in your server config. Like this:

RewriteMap tolower int:tolower

否则,该规则将导致错误。如果您没有访问您的服务器/虚拟主机的配置,然后只是注释掉规则,因为你不会要能够小写强制使用mod_rewrite。

Otherwise, that rule will result in an error. If you don't have access to your server/vhost config, then just comment out that rule, as you're not going to be able to enforce lowercase using mod_rewrite.

这篇关于转换的web.config为.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆