Aiki Tare Da Fayil .htaccess A Cikin WordPress

htaccess fayil WordPress

WordPress babban dandamali ne wanda aka inganta shi ta yadda cikakken dashboard ɗin WordPress yake da ƙarfi. Kuna iya cimma nasarori da yawa, dangane da tsara yadda rukunin yanar gizonku yake ji da ayyukansa, ta hanyar amfani da kayan aikin da WordPress ya samar muku azaman daidaitacce.

Lokaci yazo a cikin duk rayuwar mai gidan yanar gizon, duk da haka, lokacin da zaku buƙaci wuce wannan aikin. Yin aiki tare da WordPress fayil .htaccess na iya zama hanya ɗaya don yin wannan. Wannan fayil ɗin babban fayil ne wanda rukunin yanar gizan ku ya dogara da shi, kuma yafi damuwa da yadda abubuwan yanar gizo ke aiki.

Ana iya amfani da fayil ɗin .htaccess don cimma abubuwa da yawa masu amfani, kodayake. Mun riga mun rufe wasu daga cikinsu, gami da tsarin aiwatarwa regex turawa a cikin WordPress, da karin bayyani kan rubutun kai tsaye zuwa WordPress. A cikin waɗannan jagororin biyu, mun sami dama da gyara fayil ɗin .htaccess, amma ba tare da yin bayani sosai game da dalilin da yasa fayil ɗin yake can da fari ba, da kuma yadda zaku iya amfani da shi.

Wannan shine dalilin wannan labarin. Da farko, zamu kalli abin da fayil din .htaccess yayi a daidaitaccen saitin WordPress. Bayan haka, zamuyi bayanin yadda zaku iya samunta, da kuma yadda zaku iya gyara shi. A ƙarshe, za mu nuna muku dalilin da ya sa kuke son yin hakan.

Menene Fayil .htaccess?

Bari mu fara samo kayan yau da kullun. Fayil .htaccess ba fasaha bace a Fayil na WordPress. Ko kuma, don sanya shi mafi daidai, fayil ɗin .htaccess a zahiri shine fayil ɗin da masu amfani da yanar gizo na Apache ke amfani dashi. Wannan shi ne tsarin a halin yanzu ana amfani dashi ta mafi yawan shafukan yanar gizo na WordPress da rundunoni. Saboda yaduwar Apache idan ya zo ga gudanar da shafukan WordPress, kowane irin wannan rukunin yanar gizon yana da fayil na .htaccess.

Fayil .htaccess ya raba wasu halaye tare da sauran fayilolin da rukunin yanar gizonku ke amfani dasu don daidaitawa. Sunan filen ɗin fayil ɗin ɓoyayye ne kuma ana buƙatar ɓoye shi don gyara. Hakanan yana zaune a cikin kundin adireshin rukunin yanar gizonku na WordPress.

Ka tuna, fayil ɗin .htaccess yana yin abu ɗaya da abu ɗaya kawai: yana ƙayyade yadda ake nuna abubuwan da ke cikin shafin ka. Shi ke nan. 

Oye a bayan wannan bayanin mai sauƙi abu ne mai rikitarwa da yawa, kodayake. Wannan saboda yawancin masu mallakar yanar gizo, plugins, da jigogi suna yin canje-canje ga hanyar da ake amfani da permalinks a cikin shafin yanar gizonku na WordPress. Duk lokacin da ku (ko wani abin talla) kuka canza hanyar da permalinks ɗinku suke aiki, waɗannan canje-canjen suna adana cikin fayil ɗin .htaccess. 

A ka'ida, wannan kyakkyawan tsari ne mai kyau, kuma amintacce ne. Koyaya, a cikin duniyar gaske tana iya ƙirƙirar matsaloli na ainihi. Daya shine saboda 75% na masu haɓakawa suna amfani da JavaScript, kuma sabili da haka basu da sauƙi ta amfani da Apache, yawancin plugins na iya sake rubuta fayil ɗin .htaccess ta hanyar da zata bar rukunin yanar gizonku cikin tsaro. Gyarawa (ko kuma har ma da tabo) irin wannan batun ya fi ƙarfinmu a nan, amma daidaitattun fa'idodi game da ƙari suna aiki - kawai shigar da waɗanda kuka amince da su, kuma ana sabunta su akai-akai don gyara ramuka na tsaro kamar wannan.

Neman Kuma Gyara Fayil din .htaccess

Duk da cewa fayil din .htaccess an tsara shi ne musamman don rike abubuwan da suke faruwa a shafin ka, zaka iya shirya fayil din dan samun nasarori masu amfani: wadannan sun hada da yin sauyi, ko kuma inganta tsaro a shafin ka ta hanyar takaita hanyar zuwa shafuka na musamman.

A wannan sashin, za mu nuna muku yadda ake yin hakan. Amma da farko… 

GARGADI: Gyara fayil .htaccess na iya karya shafin yanar gizan ku. 

Yin kowane canje-canje ga fayilolin asali waɗanda rukunin yanar gizonku ke gudana yana da haɗari. Ya kammata ka koyaushe madadin shafinku kafin yin kowane canje-canje a gare shi, da gwaji ba tare da shafi shafin yanar gizo kai tsaye ba. 

A zahiri, akwai kyakkyawan dalili da yasa fayil ɗin .htaccess baya samuwa ga mafi yawan masu amfani da WordPress. WordPress yana da cikakken kaso na kasuwa don ƙananan rukunin yanar gizon kasuwanci, kuma wannan yana nufin cewa yawancin masu amfani da su, za mu ce, ba mafi ƙarancin fasaha ba. Wannan shine dalilin da ya sa aka ɓoye fayil din .htaccess ta tsohuwa - don kauce wa masu amfani da ƙwarewa waɗanda ke yin kuskure.

Samun dama da Edita Fayil din .htaccess

Tare da duk wannan daga hanyar, bari mu kalli yadda zaku iya samun damar fayil ɗin .htaccess. Domin yin hakan:

  1. Irƙiri haɗin yanar gizon ta amfani da abokin ciniki na FTP. Akwai wadatattun kyauta, manyan abokan FTP a waje, gami da FileZilla. Karanta takardun da aka bayar don yin haɗin FTP zuwa rukunin yanar gizonku.
  2. Da zarar ka kafa haɗin FTP, za a nuna maka duk fayilolin da suka ƙunshi rukunin yanar gizon ka. Yi duba cikin waɗannan manyan fayilolin, kuma za ku ga wanda ake kira tushen tushen.
  3. A cikin wannan babban fayil ɗin, zaku ga fayil ɗinku .htaccess. Kullum zai kasance kusa da saman jerin fayiloli a wannan babban fayil ɗin. Danna fayil ɗin, sannan danna danna / gyara. 
  4. Fayil din zai bude a cikin editan rubutu.

Kuma shi ke nan. Yanzu an baku damar yin canje-canje ga fayil ɗinku, amma lura da cewa mai yiwuwa ba kwa son yin hakan. Za mu nuna muku yadda ake amfani da wannan fayil ɗin a sashe na gaba, amma kafin mu yi yana da kyau a yi yi kwafin gida na fayil dinka .htaccess (ta amfani da misali na "adanawa"), yi canje-canjenka a cikin gida, sannan ka loda file din zuwa wani shafin da aka sanya su (kamar yadda muka ambata a sama).

Amfani da Fayil .htaccess

Yanzu kun shirya don fara amfani da ƙarin aikin da aka samar ta fayil ɗin .htacess. Bari mu fara da wasu basican asali.

  • 301 turawa - Canza wurin 301 karamin yanki ne na lamba wannan yana aika baƙi daga wannan shafi zuwa wani, kuma ya zama dole idan kun canza wurin wani shafi wanda yake da alaƙa da shi daga wani shafin yanar gizo. A madadin, zaku iya amfani da fayil ɗin .htaccess don tura shafin yanar gizon. Hakanan zaka iya jagorantar baƙi daga tsohuwar hanyar HTTP ta shafin zuwa sabon, mafi aminci, sigar HTTPS. Sanya wannan a cikin fayil din .htacess:

Redirect 301 /oldpage.html /newpage.html

  • Tsaro - Hakanan akwai hanyoyi da yawa don amfani da fayil ɗin .htaccess don amfani da dabarun tsaro na ci gaba na WP. Daya daga cikin wadannan shine kulle hanyoyin samun fayiloli musamman ta yadda masu amfani kawai tare da ingantaccen ingantacce za su iya samun damar ainihin fayilolin da rukunin yanar gizonku ke gudana. Kuna iya amfani da wannan lambar, wanda aka haɗa zuwa ƙarshen fayil ɗin ku .htaccess, don iyakance damar isa ga wasu manyan fayiloli:

<FilesMatch "^.*(error_log|wp-config\.php|php.ini|\.[hH][tT][aApP].*)$">
Order deny,allow
Deny from all
</FilesMatch>

  • Gyara URLs - Wani fasali mai amfani na fayil din .htaccess, duk da cewa yafi hadadden aiwatarwa, shine cewa ana iya amfani da fayil din don sarrafa hanyar da ake nuna URLs lokacin da baƙi suka shiga shafinku. Don yin hakan, kuna buƙatar tabbatar kuna amfani da sabon samfurin Apache. Wannan ya sanya URL ɗin shafi ɗaya ya bayyana daban-daban ga baƙi. Wannan misalin na ƙarshe shine - watakila - ɗan rikitarwa ne ga yawancin masu amfani kawai suna amfani da fayil din .htaccess. Koyaya, Na haɗa shi don nuna muku iyakar abin da za'a iya cimma tare da fayil ɗin. Sanya wannan zuwa fayil ɗin ku .htaccess:

RewriteEngine on
RewriteRule ^oranges.html$ apples.html

Ci gaba da Ci gaba Tare da .htaccess

Aiki tare da .htaccess fayil wata babbar hanya ce don koyo game da yadda shafin yanar gizan ku na WordPress yake aiki a matakin mafi mahimmanci, kuma ya baku hango girman fa'idodi don keɓancewa wanda har ma da gidan yanar gizo na WP mai daidaituwa zai baku dama. Da zarar kun ƙware a aiki tare da fayil .htaccess ta hanyar yin canje-canje na asali waɗanda muka bayyana a sama, yawancin zaɓuɓɓuka zai buɗe muku. Daya, kamar yadda muka gabata, shine iyawa sake saita shafin yanar gizonku na WordPress

Wani kuma shine yawancin hanyoyin inganta ingantaccen tsaro na WordPress sun haɗa da canza fayil ɗin .htaccess kai tsaye, ko amfani da tsarin FTP ɗaya don yin canje-canje ga wasu fayilolin tushen. A takaice dai, da zarar ka fara duba kwayoyi da madogara na rukunin yanar gizon ka, za ka ga damar da ba ta da iyaka don keɓancewa da haɓakawa.

Me kuke tunani?

Wannan shafin yana amfani da Akismet don rage spam. Koyi yadda aka sarrafa bayanan bayaninka.