SSD WindowsWindows

Chuyển .htaccess sang web.config

Như chúng ta đã biết file cấu hình rất quan trong cho host của chúng ta (.htaccess hoặc web.config) bài hôm nay chúng ta sẽ sử dụng công cụ IIS manager để chuyển .htaccess sang web.config

Việc này phục vụ rất nhiều cho chúng ta khi dùng web trên host linux… sang host windows

Chuyển .htaccess của wordpress sang web.config để dùng trên host windows

Ta có file htaccess có nội dung

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Các bước chuyển đổi như sau.

1. Bật IIS bằng cách Click vào Start -> Tìm Internet Information Services (IIS) Manager

2. Sau đó mở URL Rewrite lên. Nếu chưa có URL Rewrite thi bạn có thể down tại đây và cài đặt.

3. Click vào Import Rules

4. Cuối cùng các bạn chỉ cần paste đoạn code .htaccess vào ô Rewrite rules tự động sẽ có kết quả tại Converted Rules

Đã hoàn thành rồi đó chỉ việc lấy code XML bên tab Xml View là được.

5. Sau đó import đoạn mã XML trên vào file web.config

<rewrite>
  <!--This directive was not converted because it is not supported by IIS: RewriteBase /.-->
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^index\.php$" ignoreCase="false" />
      <action type="None" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url="." ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.php" />
    </rule>
  </rules>
</rewrite>

Nếu bạn nào dùng wordpress chuyển sang host windows bị lỗi đường dẫn thì có thể copy đoạn code trên cho vào web.config là được.

Chúc các bạn thành công.

 

Bài viết liên quan

Back to top button