Hướng dẫn iis hide php extension - iis ẩn phần mở rộng php

Tôi đang chuyển một ứng dụng Web PHP từ Linux sang IIS 7. Những gì tôi cần làm là ẩn mọi thứ nói PHP, vì vậy phần mở rộng URL và liên kết chủ yếu. Tôi không nghĩ rằng có bất kỳ thứ nào khác cần phải được ẩn vì chúng không chơi. Bất kỳ đề xuất?

Hướng dẫn iis hide php extension - iis ẩn phần mở rộng php

Pratik

11.3K22 Huy hiệu vàng67 Huy hiệu bạc99 Huy hiệu đồng22 gold badges67 silver badges99 bronze badges

Hỏi ngày 8 tháng 8 năm 2011 lúc 20:27Aug 8, 2011 at 20:27

1

Hãy xem tùy chọn expose_php trong php.ini, cũng như mod_rewrite được đề xuất.

Đã trả lời ngày 8 tháng 8 năm 2011 lúc 20:36Aug 8, 2011 at 20:36

ShishiShi

4.1301 Huy hiệu vàng25 Huy hiệu bạc31 Huy hiệu đồng1 gold badge25 silver badges31 bronze badges

ISAPI_REWRITE là một giải pháp thay thế tốt cho mod_rewrite trên Apache; Chúng tôi đã sử dụng nó trên một số dự án được triển khai trên Windows+IIS. Cú pháp giống như mod_rewrite và nó hỗ trợ tất cả các tính năng tôi từng phải sử dụng trên Apache mod_rewrite.

Có một phiên bản miễn phí bạn có thể sử dụng áp dụng các quy tắc cho mọi trang web trên máy chủ; Nếu bạn sáng tạo, bạn có thể sử dụng RewriteCond để giới hạn chúng vào các miền cụ thể được ánh xạ tới các trang web. Phiên bản trả phí cũng có giá trị chi phí nếu đó là trong ngân sách của bạn.

http://www.helicontech.com/isapi_rewrite/

Đã trả lời ngày 8 tháng 8 năm 2011 lúc 20:42Aug 8, 2011 at 20:42

Hướng dẫn iis hide php extension - iis ẩn phần mở rộng php

Trên IIS 7 Sử dụng mô -đun viết lại URL IIS gốc. ISAPI_REWRITE là lựa chọn thay thế tốt nhất của bạn nếu triển khai trên IIS 6 hoặc sớm hơn.

Mô -đun viết lại URL cũng có thể nhập hầu hết các quy tắc mod_rewrite ra khỏi .htaccess nếu điều đó cũng có ích.

Bắt đầu tại đây http://iis.net/urrewrite

Đã trả lời ngày 8 tháng 8 năm 2011 lúc 22:30Aug 8, 2011 at 22:30

Hướng dẫn iis hide php extension - iis ẩn phần mở rộng php

Mark Brown Màu nâuMark Brown

6,9072 Huy hiệu vàng16 Huy hiệu bạc20 Huy hiệu Đồng2 gold badges16 silver badges20 bronze badges

Để thực hiện điều này trên máy chủ của mình, tôi đã phải đầu tiên: Cài đặt mô-đun URL REWRTIE http://www.iis.net/doads/microsoft/url-rewrite

Và sau đó tôi đã phải thêm một tệp web.config với XML này (điều này hoạt động để xóa .php, nếu được thêm vào, cũng như thêm .PHP vô hình vào URL):

    

    
        
            
                
                    
                    
                        
                    
                    
                
                
                    
                    
                        
                        
                        
                    
                    
                
            
        
    

Đã trả lời ngày 10 tháng 11 năm 2015 lúc 14:47Nov 10, 2015 at 14:47

Đôi khi, điều quan trọng là phải xóa - hoặc ẩn phần mở rộng tệp của các tập lệnh bạn sử dụng. Bảo mật bằng cách tối nghĩa có thể là lý do đó, nếu bạn không muốn người khác biết ngôn ngữ tập lệnh bạn đang sử dụng cho trang web của mình hoặc cho máy chủ trang web tĩnh. Ví dụ này sẽ ẩn tiện ích mở rộng .php bằng cách sử dụng mô -đun viết lại URL IIS, trong một sẵn sàng để sử dụng Web.Config & .htaccess Ví dụ: Mở rộng ít URL trong IIS.extension less URLs in IIS.

Tại sao cần phải ẩn các phần mở rộng tệp trong URL?

Tôi không phải là fan hâm mộ của bảo mật bằng cách tối nghĩa và tôi chưa bao giờ gặp phải điều này là kết quả của việc quét bảo mật.security by obscurity, and I have never encountered this as the result outcome of a security scan.

Bảo mật bằng cách tối nghĩa là một lý do để ẩn tiện ích mở rộng tệp trong URL, nếu bạn không muốn người khác biết ngôn ngữ tập lệnh bạn đang sử dụng cho trang web của mình. Tối ưu hóa công cụ tìm kiếm (SEO) là một lý do hợp lệ khác hoặc có lẽ bạn chỉ muốn ẩn tiện ích mở rộng tệp mà không có lý do rõ ràng.

Cũng không có lợi ích cho SEO, theo như tôi biết.

Tuy nhiên, bạn có thể sử dụng kỹ thuật này để rút ngắn URL, một chút. Nó không loại bỏ bốn đến năm ký tự từ URL (Hồi .Php ,, Và một số người nói rằng một trang web hoạt động nhanh hơn vì máy chủ web có thể khớp URL mà không cần mở rộng cho các thư mục (thư mục) nhanh hơn URL, với phần mở rộng cho một tệp. Một số người nói. Tôi không có dữ liệu hoặc thêm thông tin về điều này.

Dưới đây là một ví dụ mô -đun viết lại URL IIS để bạn ẩn tiện ích mở rộng trong URL.

Kỹ thuật này còn được gọi là multiviews hoặc đàm phán nội dung ở Apache và những người khác gọi nó là URL không có phần mở rộng. Xem bên dưới để biết ví dụ để sử dụng với .htaccess trong IIS.

Giới thiệu về đa điểm, hoặc đàm phán nội dung:MultiViews, or content negotiation:

Hiệu ứng của đa lượt xem như sau: nếu máy chủ nhận được yêu cầu/một số/dir/foo, nếu/some/drid có kích hoạt đa lượt xem và/một số/dir/foo không tồn tại, thì máy chủ đọc thư mục đang tìm kiếm Các tệp có tên foo.*, và thực hiện một cách hiệu quả một bản đồ loại đặt tên cho tất cả các tệp đó, gán cho chúng cùng các loại phương tiện và mã hóa nội dung mà nó sẽ có nếu khách hàng đã yêu cầu một trong số chúng theo tên. Sau đó, nó chọn phù hợp nhất với các yêu cầu của khách hàng.

Đặt các bản viết lại sau trong tệp web.config để ẩn tiện ích mở rộng .php trong URL của bạn. Chà, ví dụ không thực sự ẩn .php khỏi URL, nhưng điều này cho phép bạn sử dụng URL không mở rộng như

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
0.hide the .php extension in your URL’s. Well, the example doesn’t really hide .php from the URL, but this allows you to use extension-less URL’s like

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
0.

Mô -đun viết lại URL IIS, thêm phần .php vào URL trong nền.

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)

Đối với các yêu cầu đã chứa tiện ích mở rộng .php

Một ví dụ mở rộng hơn là chuyển hướng tất cả các yêu cầu với .php trong URL sang biến thể không mở rộng của chúng. Vì vậy, khi một khách truy cập đến qua

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
2, phần mở rộng bị tước và anh ta sẽ được chuyển đến

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
3.

Quy tắc viết lại của chúng tôi Bản đồ yêu cầu cuối cùng đó trở lại Index.php mà không hiển thị tiện ích mở rộng.

<rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

Code language: HTML, XML (xml)

Luôn luôn kiểm tra các ví dụ như vậy trước khi đưa nó vào sản xuất.

Mô phỏng đa lượt xem Apache trong IIS bằng tệp .htaccess và APE Helicon

Nếu bạn sử dụng .htaccess trong IIS, bạn có thể tạo cùng một hiệu ứng đa lượt xem để ẩn tiện ích mở rộng .PhP. Để điều này xảy ra, bạn phải khai báo một vài điều kiện viết lại và viết lại các quy tắc (

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
4 và

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
5). Phần gọn gàng là, điều này cũng sẽ hoạt động với Linux, Apache và Mod_rewrite, làm cho giải pháp này đa nền tảng!

Multiviews .htaccess example trong tệp

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
6 của bạn, thêm cấu hình viết lại sau:
In your

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
6 file, add the following rewrite configuration:

# Enable the Rewrite Engine RewriteEngine On # Match a folder name, www.example.com/dev/ in this case RewriteBase /dev/ # SEO URL's for PHP files RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Hide the .php extension to prevent double content RewriteRule ^(.+).php$ $1 [NC,L,R=301] # Rewrite to, and present the contents of the .php files, # if there is no file extension in the URL. # For example: /foo shows /foo.php RewriteRule ^([^/]+)(?:/(.+))?$ $1.php?(?2p=$2) [L]

Code language: PHP (php)

.htaccess rules explanation:The first code block uses two

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
4 checks to verify whether or not the URL is a file or folder. Điều này đầy đủ hơn, rõ ràng và nhanh hơn để tạo ra một ngoại lệ cho mọi loại tệp có thể.

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
5 viết lại URL - mà chủ yếu không chứa phần mở rộng tệp - thành tệp PHP có tên đó.

The first code block uses two

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
4 checks to verify whether or not the URL is a file or folder. This is more complete, clear and faster than to create an exception for every file type possible. The

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
5 rewrites the URL – that mostly doesn’t contain a file extension – to a PHP file with that name.

Mẫu

<configuration> <system.webServer> <rewrite> <rules> <rule name="hide .php extension" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> conditions> <action type="Rewrite" url="{R:1}.php" /> rule> rewrite> system.webServer> configuration>

Code language: HTML, XML (xml)
9 được giải thích như sau:

  1. Các ký tự kèm theo

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    0 và

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    1 đánh dấu đầu và cuối chuỗi; ngăn chặn quy tắc đôi khi chỉ khớp với một phần của URL
  2. Nhóm

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    2 khớp với tên của tệp PHP là

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    3. Và nó tìm thấy tất cả các ký tự lên đến một dấu gạch chéo, hoặc kết thúc của chuỗi
  3. Khối

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    4 cố gắng tìm một dấu gạch chéo, theo sau là các ký tự khác và lưu nó dưới dạng

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    5

Thay thế

<rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

Code language: HTML, XML (xml)
6 sử dụng tham chiếu có điều kiện:

  • Chuỗi truy vấn chứa đầy

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    7 nếu

    <rewrite> <rules> <rule name="Redirect .php extension" stopProcessing="false"> <match url="^(.*).php$" ignoreCase="true" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(.*).php$" ignoreCase="false" /> conditions> <action type="Redirect" url="{R:1}" redirectType="Permanent" /> rule> <rule name="hide .php extension" stopProcessing="true"> <match url="^(.*)$" ignoreCase="true" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}.php" matchType="IsFile" /> conditions> <action type="Rewrite" url="{R:0}.php" /> rule> rules> rewrite>

    Code language: HTML, XML (xml)
    5 tồn tại.

Cuối cùng, một quy tắc được thêm vào ẩn phần mở rộng .php.hides the .php extension.

Điều này ngăn một công cụ tìm kiếm tìm thấy nội dung trùng lặp và do đó ngăn chặn hình phạt cho vị trí trang web của bạn trong kết quả tìm kiếm.

Có những cách khác quá.

Xóa phần mở rộng .PHP bằng .htaccess khỏi URLS

Để xóa tiện ích mở rộng.

RewriteEngine on # Redirects example.com/file.php to example.com/file properly RewriteCond %{REQUEST_FILENAME} !-d # is not directory RewriteCond %{REQUEST_FILENAME}\.php -f # is an existing html file RewriteCond %{REQUEST_URI} ^(.+)\.php$ # request URI ends with .php RewriteRule (.*)\.php$ /$1 [R=301,L] # redirect from index.php to index

Code language: PHP (php)

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php

Hoặc sử dụng nhiều lượt xem:

Options +MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]

Điều này loại bỏ tiện ích mở rộng làm cho URL trở nên thân thiện với URL và một số công cụ tìm kiếm SEO. Sử dụng những gì phù hợp nhất cho bạn và thêm thẻ meta chính tắc trong đầu HTML của bạn để tránh nội dung trùng lặp (khi thích hợp).

Thời gian tải: 118 truy vấn, 0,250 giây sử dụng bộ nhớ byte 10908056. Sử dụng bộ nhớ cao điểm: 10928784 byte. 118 queries, 0.250 seconds using 10908056 bytes memory. Peak memory usage: 10928784 bytes.