.htaccess redirect

Ang Apache .htaccess 301 redirect ay isang server-side redirect at isang permanenteng redirect.

Kaya Ang .htaccess  file ay isang Apache server configuration file.Ang  .htacces s file ay ginagamit sa bawat direktoryo.

Ang paggamit  ng .htaccess  file ay nakakabawas sa pagganap ng server.  Dapat na iwasan ang paggamit ng .htaccess  kapag mayroon kang access sa pangunahing configuration file ng Apache server na httpd.conf.Karaniwang walang access ang mga shared hosting website sa httpd.conf file at dapat gumamit ng  .htaccess  file.

Ang 301 redirect na tugon na ito ay nag-aabiso sa mga search engine na ang pahina ay permanenteng lumipat mula sa lumang URL patungo sa bagong URL.

Inilipat din ng mga search engine ang lumang ranggo ng pahina ng URL sa bagong URL.

.htaccess redirect

Idagdag ang code na ito o lumikha ng bagong  .htaccess  file sa old-page.html na direktoryo.

Isang pag-redirect ng URL

Permanenteng pag-redirect mula sa old-page1.html patungo sa new-page.html.

.htaccess:

Redirect 301 /old-page1.html http://www.mydomain.com/new-page1.html

Buong pag-redirect ng domain

Permanenteng pag-redirect mula sa lahat ng mga pahina ng domain sa newdomain1.com.

Ang .htaccess  file ay dapat nasa root directory ng lumang website.

.htaccess:

Redirect 301 / http://www.newdomain1.com/

Pinapagana ang configuration ng .htaccess

Kung nag-upload ka  ng .htaccess  na file sa lumang-page.html na direktoryo at ang pag-redirect ay hindi gagana, kadalasan ay nangangahulugan ito na ang mga  .htaccess  na file ay hindi pinagana sa Apache server configuration file na httpd.conf.

 Maaaring paganahinang  .htaccess file sa pamamagitan ng pagdaragdag ng httpd.conf file ng Apache server.

httpd.conf:

<Directory /srv/www/rapidtable.com/public_html/web/dev/redirect>
  AllowOverride All
</Directory>

Mahalaga: hindi inirerekomenda ang setting na ito dahil pinapabagal nito ang Apache server.

httpd.conf redirect

Kung mayroon kang pahintulot na baguhin ang httpd.conf file, mas mabuting idagdag ang Redirect directive sa httpd.conf sa halip na  .htaccess  file.

Suriin kung ang library ng rewrite module na mod_rewrite.so ay na-load ng apache server:

$ apache2ctl -M

 

Idagdag ang sumusunod na code sa httpd.conf file.

Kung hindi available ang mod_rewrite.so library ng rewrite module, alisin sa komento ang unang linya para i-load ang rewrite module.

httpd.conf:

# LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
<Directory /srv/www/rapidtable.com/public_html/web/dev/redirect>
   Redirect 301 /old-page.html http://www.mydomain.com/new-page.html
</Directory>

 

Huwag kalimutang i-restart ang Apache server pagkatapos ng pag-update ng httpd.conf:

$ sudo /etc/init.d/apache2 restart

 

 

 


Tingnan din

Advertising

WEB DEVELOPMENT
°• CmtoInchesConvert.com •°