حذف web از پروژه basic در IIS در Yii2

در پروژه های basic برای حذف web در url می بایست دو کار انجام داد
ابتدا فایل web.config را در روت سایت قرار دهید با محتوای زیر


<?xml version="۱٫۰″ encoding="UTF-8″?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<rule name="asset" stopProcessing="true">
<match url="^assets/(.*)$" ignoreCase="false" />
<conditions>
<add input="{URL}" pattern="^/(assets|css)" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="web/assets/{R:1}" />
</rule>
<rule name="css" stopProcessing="true">
<match url="^css/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="web/css/{R:1}" />
</rule>
<rule name="uploads" stopProcessing="true">
<match url="^uploads/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="web/uploads/{R:1}" />
</rule>
<rule name="sitemap" stopProcessing="true">
<match url="sitemap(.xml)$" ignoreCase="false" />
<action type="Rewrite" url="web/sitemap.xml" />
</rule>
<rule name="googleanalytic" stopProcessing="true">
<match url="google53bd83fefbea336b(.html)$" ignoreCase="false" />
<action type="Rewrite" url="web/google53bd83fefbea336b.html" />
</rule>
<rule name="web" stopProcessing="true">
<match url="^.*$" ignoreCase="false" />
<action type="Rewrite" url="web/" />
</rule>
<!–This rule was not converted because only some of the conditions are using the OR flag.–>
</rules>
</rewrite>
</system.webServer>
</configuration>

سپس در فولدر config و در فایل web.php کد زیر را قرار دهید


$config = [
'components' => [
'request' => [
'baseUrl' => $baseUrl,
],
'urlManager' => [
'baseUrl' => $baseUrl,
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>' => '/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '/',
'<controller:\w+>/<action:\w+>' => '/',
'product/' => 'product/slug',
],
],
],
];

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *