Bagaimana cara menyembunyikan ekstensi php di url?

Terkadang penting untuk menghapus -atau menyembunyikan- ekstensi file skrip yang Anda gunakan. Keamanan dengan ketidakjelasan mungkin menjadi alasan itu, jika Anda tidak ingin orang lain mengetahui bahasa skrip apa yang Anda gunakan untuk situs web Anda, atau untuk host situs statis. Contoh ini akan menyembunyikan ekstensi .php_ menggunakan IIS URL Rewrite Module, di web siap pakai. konfigurasi &. contoh htaccess. ekstensi kurang URL di IIS

Daftar isi

Mengapa perlu menyembunyikan ekstensi file di URL?

Saya bukan penggemar keamanan karena ketidakjelasan, dan saya belum pernah menemukan ini sebagai hasil dari pemindaian keamanan

Keamanan dengan ketidakjelasan adalah salah satu alasan untuk menyembunyikan ekstensi file di URL, jika Anda tidak ingin orang lain mengetahui bahasa skrip apa yang Anda gunakan untuk situs web Anda. Search Engine Optimization (SEO) adalah alasan sah lainnya, atau mungkin Anda hanya ingin menyembunyikan ekstensi file tanpa alasan yang jelas

Juga tidak ada manfaat untuk SEO, sejauh yang saya tahu

Namun Anda dapat menggunakan teknik ini untuk sedikit mempersingkat URL. Memang memangkas empat hingga lima karakter dari URL (“. php”, “. html”, “. aspx”). Dan ada yang mengatakan kinerja situs web lebih cepat karena server web dapat mencocokkan URL tanpa ekstensi ke folder (direktori) lebih cepat daripada URL dengan ekstensi ke file. Beberapa orang mengatakan. Saya tidak punya data atau informasi lebih lanjut tentang ini

Bersembunyi. php dengan Modul Penulisan Ulang URL di IIS

Berikut adalah contoh Modul Penulisan Ulang URL IIS untuk Anda sembunyikan. ekstensi php di URL

Teknik ini juga dikenal sebagai Multiviews atau Negosiasi Konten di Apache, dan yang lainnya menyebutnya URL tanpa ekstensi. Lihat di bawah untuk contoh penggunaan. htaccess di IIS

Tentang MultiViews, atau negosiasi konten

Efek MultiViews adalah sebagai berikut. jika server menerima permintaan untuk /some/dir/foo, jika /some/dir mengaktifkan MultiViews, dan /some/dir/foo tidak ada, maka server membaca direktori mencari file bernama foo. *, dan secara efektif memalsukan peta jenis yang menamai semua file tersebut, menugaskan mereka jenis media dan pengkodean konten yang sama jika klien meminta salah satu dari mereka dengan nama. Kemudian memilih yang paling cocok dengan kebutuhan klien

Letakkan penulisan ulang berikut dalam file web.config untuk menyembunyikan. ekstensi php di URL Anda. Nah, contohnya tidak terlalu tersembunyi. php dari URL, tetapi ini memungkinkan Anda untuk menggunakan URL tanpa ekstensi seperti www.example.com/index

Modul Penulisan Ulang URL IIS menambahkan bagian .php ke URL di latar belakang

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

Mengubah. htaccess ke web. config
Larang akses langsung ke file PHP di wp-content/uploads/
SSL di WordPress. bagaimana cara memindahkan WordPress ke HTTPS?

Untuk permintaan yang sudah berisi a. ekstensi php

Contoh yang lebih luas adalah mengarahkan ulang semua permintaan dengan. php di URL ke varian tanpa ekstensi mereka. Jadi, ketika pengunjung masuk melalui

<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, ekstensi dihapus dan dia akan diarahkan ke

<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

Aturan penulisan ulang kami memetakan permintaan terakhir itu kembali ke indeks. php tanpa menampilkan ekstensi

<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)_

Selalu uji contoh seperti itu sebelum memasukkannya ke dalam produksi

Meniru Apache Multiviews di IIS menggunakan a. htaccess dan Helicon Ape

Jika Anda menggunakan. htaccess di IIS Anda dapat membuat efek Multiviews yang sama untuk menyembunyikannya. ekstensi php. Agar hal ini terjadi, Anda harus mendeklarasikan beberapa ketentuan penulisan ulang dan aturan penulisan ulang (

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

<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). Bagian yang rapi adalah, ini juga harus bekerja dengan Linux, Apache dan mod_rewrite, membuat solusi ini lintas platform

Multiview. contoh htaccess
Di file

<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 Anda, tambahkan konfigurasi penulisan ulang berikut

# 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: Apache (apache)

penjelasan aturan htaccess
Blok kode pertama menggunakan dua

<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 pemeriksaan untuk memverifikasi apakah URL adalah file atau folder atau bukan. Ini lebih lengkap, jelas, dan lebih cepat daripada membuat pengecualian untuk setiap jenis file yang memungkinkan.

<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 menulis ulang URL – yang sebagian besar tidak berisi ekstensi file – menjadi file PHP dengan nama itu

Pola

<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 dijelaskan sebagai berikut

  1. Karakter penutup

    <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)8 dan

    <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)9 menandai awal dan akhir string;
  2. Grup

    # 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: Apache (apache)_0 cocok dengan nama file PHP sebagai

    # 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: Apache (apache)1. Dan itu menemukan semua karakter hingga garis miring, atau akhir string
  3. Blok

    # 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: Apache (apache)_2 mencoba menemukan garis miring, diikuti oleh karakter lain, dan menyimpannya sebagai

    # 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: Apache (apache)3

Pengganti

# 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: Apache (apache)_4 menggunakan referensi bersyarat

  • String kueri diisi dengan

    # 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: Apache (apache)5 jika

    # 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: Apache (apache)3 ada

Akhirnya, aturan ditambahkan yang menyembunyikan. ekstensi php

Ini mencegah mesin pencari menemukan konten duplikat, dan dengan demikian mencegah penalti untuk posisi situs Anda dalam hasil pencarian. Ada cara lain juga

Tulis ulang Proxy dengan. htaccess di IIS

Menghapus. ekstensi php dengan. htaccess dari URL

Untuk menghapus. ekstensi php dari URL dengan. htaccess, Anda dapat menyimpan yang berikut ini di file baru. file htaccess

<IfModule mod_rewrite.c> 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 </IfModule>

Code language: Apache (apache)

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

Code language: Apache (apache)

Atau gunakan MultiViews

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

Ini menghapus ekstensi yang membuat URL lebih banyak pengguna dan -beberapa mengatakan- ramah mesin pencari SEO. Gunakan yang terbaik untuk Anda, dan tambahkan tag meta kanonis di kepala HTML Anda untuk menghindari duplikat konten (jika perlu)

Bagaimana cara menyembunyikan ekstensi file php di URL?

Dengan menonaktifkan expose_php di php Anda. ini file , Anda mengurangi jumlah informasi yang tersedia untuk mereka. Agar ini berfungsi secara efektif, Anda harus mengganti nama file PHP Anda dengan ekstensi di atas.

Bagaimana cara menyembunyikan. html di URL?

Itu. html dapat dihapus dengan mudah dengan mengedit file. file htaccess .

Bagaimana cara menghapus indeks php dari URL?

Untuk menghapus “index. php” dari URL situs Anda, pertama-tama Anda harus memastikan server Anda diatur untuk meneruskan permintaan calon 404 ke indeks Craft. file php di balik layar . Jika Anda menjalankan Apache, Anda dapat melakukannya dengan membuat pengalihan di situs Anda.

Bagaimana cara menghapus ekstensi dari php?

Anda dapat menggunakan fungsi substr() dan strrpos() untuk mengambil nama file tanpa ekstensi di PHP . $namafile = 'namafile. php'; . "));

Postingan terbaru

LIHAT SEMUA