คลังเก็บป้ายกำกับ: URL

rewrite url ใน IIS

โดยปกติ PHP จะใช้ Apache HTTP Server เป็น server ถ้าต้องการให้ URL เรียบร้อยสวยงามก็ใช้ไฟล์ .htaccess แต่ถ้าเราใช้ Internet Information Services ( IIS ) ก็ต้องไปใช้ไฟล์ ที่คู่กันคือ Web.Config แทน

การที่จะ rewrite url ใน iis จะต้องมีการติดตั้ง URL Rewrite extension เอาไว้ก่อน

ตัวอย่างไฟล์ Web.Config ที่ทำหน้าที่ แปลง ค่าใน URL ไปให้ไฟล์ index.php โดยที่จะซ่อนไฟล์ index.php ออกจาก url

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
      <rewrite>
         <rules>
            <clear />
            <rule name="remove index.php" patternSyntax="Wildcard">
               <match url="*" />
               <conditions>
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
               </conditions>
               <action type="Rewrite" url="index.php" />
            </rule>
         </rules>
      </rewrite>
   </system.webServer>
</configuration>

นำไปว่างใน folder ที่ต้องการใช้ เช่น folder public ของ Laravel เป็นต้น