首页 > 解决方案 > 在 IIS 服务器中使用 htaccess 更改主 URL

问题描述

我正在 IIS 服务器上使用 laravel 5.6 项目。

我想使用 htaccess 更改 domain.com/domain.com/something我的项目的主要 url,但我找不到任何东西。

这是我当前的 .htaccces 文件

选项 -MultiViews -Indexes

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

有什么帮助吗?

标签: laravel.htaccessuriiis-10

解决方案


根据 htaccess 文件内容,我已经转换了 IIS UrlRewrite 规则中的规则。要应用这些规则,请在您的网站根目录中创建 web.config 文件并粘贴以下内容。如果文件已经存在,只需复制该rewrite部分

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rule 1" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{URL}" pattern="(.+)/$" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" redirectType="Permanent" />
                </rule>
                <rule name="Rule 2" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
               <rule name="redirect" stopProcessing="true">
                 <match url="^$" />
                   <action type="Redirect" url="/subdir" />
               </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

推荐阅读