Ṣe atunṣe Awọn ibeere Oju opo wẹẹbu Ti o da lori Ẹrọ aṣawakiri Ti a Lo (Chrome, Firefox tabi IE)


Gẹgẹbi a ti ṣe ileri ninu nkan ti tẹlẹ wa (Bii o ṣe le ṣe atunṣe Redirection ti inu pẹlu mod_rewrite), ni ipo yii a yoo ṣe alaye bi o ṣe le ṣe afihan akoonu oju opo wẹẹbu aṣa nipa lilo awọn ibeere atunṣe Apache mod_rewrite ti o da lori awọn ilana aṣawakiri aṣàmúlò.

Ni iṣaro, gbogbo awọn aṣawakiri igbalode yẹ ki o tumọ akoonu bakanna. Sibẹsibẹ, diẹ ninu ṣe awọn ẹya tuntun ni iyara ju awọn omiiran lọ. Lati le ni oju opo wẹẹbu iṣẹ-ṣiṣe ni kikun ti ko fọ nigbati o ba wo ni lilo ẹrọ lilọ kiri ayelujara kan. Laanu, eyi yoo nilo itọsọna si itọsọna miiran tabi oju-iwe miiran.

Awọn ofin atunkọ atẹle yoo ṣe atunṣe awọn ibeere fun tecmint.html si tecmint-chrome.html, tecmint-firefox.html, tabi tecmint-ie.html da lori ẹrọ lilọ kiri ayelujara ti nlo (Google Chrome, Mozilla Firefox, tabi Internet Explorer).

Lati ṣe bẹ, oniyipada ayika HTTP_USER_AGENT lati ṣe idanimọ aṣawakiri ti o da lori okun oluranlowo olumulo. Nibi a ṣe agbekalẹ itọsọna RewriteCond , eyiti o fun laaye wa lati ṣafihan ipo kan ti o gbọdọ pade ni ibere fun itọsọna naa lati waye.

RewriteCond "%{HTTP_USER_AGENT}"  ".*Firefox.*"
RewriteRule "^/tecmint\.html$"     	"/tecmint-firefox.html" [R,L]
RewriteCond "%{HTTP_USER_AGENT}"  ".*Chrome.*"
RewriteRule "^/tecmint\.html$"     	"/tecmint-chrome.html" [R,L]
RewriteCond "%{HTTP_USER_AGENT}"  ".*Trident.*"
RewriteRule "^/tecmint\.html$"     	"/tecmint-ie.html" [R,L]

Jọwọ ṣe akiyesi pe oju-iwe oju-iwe afojusun tecmint.html ko ni dandan lati wa tẹlẹ. Ni akọkọ, jẹ ki a ṣẹda tecmint-firefox.html, tecmint-chrome.html, ati tecmint-ie.html pẹlu awọn akoonu wọnyi.

<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
	<title></title>
  </head>
  <body>
	<h3>Welcome to Tecmint on Firefox!</h3>
  </body>
</html>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
	<title></title>
  </head>
  <body>
	<h3>Welcome to Tecmint on Chrome!</h3>
  </body>
</html>
<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
	<title></title>
  </head>
  <body>
	<h3>Welcome to Tecmint on Internet Explorer!</h3>
  </body>
</html>

a yoo rii abajade ti lilọ kiri ayelujara si tecmint.html nipa lilo awọn aṣawakiri oriṣiriṣi:

Bi o ti le rii, awọn ibeere fun tecmint.html ni a darí ni ibamu da lori ẹrọ lilọ kiri ayelujara ti o lo.

Ninu àpilẹkọ yii a ti jiroro bi a ṣe le ṣe awọn ibeere atunṣe ti o da lori ẹrọ aṣawakiri olumulo. Lati fi ipari si, Emi yoo ṣeduro ni gíga ki o wo itọsọna ti o ku ninu awọn docs Apache fun itọkasi ọjọ iwaju.

Gẹgẹbi igbagbogbo, ni ọfẹ lati lo fọọmu asọye ni isalẹ ti o ba ni ibeere eyikeyi tabi esi nipa nkan yii. A n reti lati gbọ lati ọdọ rẹ!