Search code examples
laravel.htaccessuriiis-10

Change main URL with htaccess in IIS server


I'm working with laravel 5.6 project on a IIS server.

I would like to change domain.com/ to domain.com/something as a main url for my project using htaccess but I cannot find anything.

This is my current .htaccces file

Options -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]

Any help?


Solution

  • Based on the htaccess file contents I have converted the rules in IIS UrlRewrite rules. For applying these rules, create web.config file in your website root directory and paste the following contents. If a file already exists just copy the rewrite section

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