موقع بوابة بلاد الشام ،belad-alsham
عزيزي آلزآئر
دعوة للانضمام قروب أهل الشام
موقع بوابة بلاد الشام ،belad-alsham
عزيزي آلزآئر
دعوة للانضمام قروب أهل الشام
موقع بوابة بلاد الشام ،belad-alsham
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.



 
الرئيسيةمجلة الشام آخباأحدث الصورالتسجيلدخولrss
قيّم موقع الشام من هنا

مساحة اعلانية br /> مساحة اعلانية
مساحة اعلانية
مساحة اعلانية

 

 أباتشي خادم HTTP الإصدار 2.0

اذهب الى الأسفل 
كاتب الموضوعرسالة
apache
اعضاء فعالين
اعضاء فعالين
apache


عدد المشاركات : 123
نقاط : 227
التقيم : 20
تاريخ الميلاد : 15/03/1990
تاريخ التسجيل : 14/08/2012
العمر : 34

أباتشي خادم HTTP الإصدار 2.0 Empty
مُساهمةموضوع: أباتشي خادم HTTP الإصدار 2.0   أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء أغسطس 14, 2012 9:59 am

أباتشي خادم HTTP الإصدار 2.0



أباتشي خادم HTTP الإصدار 2.0 Left
أباتشي > HTTP خادم > التوثيق > الإصدار 2.0 > وثائق متنوعة
يرجى ملاحظة

هذه الوثيقة يشير إلى الإصدار 2.0 من هتبد أباتشي، الذي لم يعد الموصى بها.
إذا كنت تستخدم الإصدارات الحالية من هتبد (2.2 أو 2.4)، يرجى زيارة الوثائق الخاصة بهم بدلا من ذلك:
قد اتبع هذا الرابط للذهاب إلى الإصدار 2.2 من هذه الوثيقة.


إعادة كتابة عنوان الدليل


اللغات المتاحة: EN | كو

كتبت أصلا من قبل س. رالف <rse@apache.org> Engelschall ديسمبر 1997


هذه الوثيقة استكمالا لل mod_rewrite الوثائق المرجعية . ويصف التقرير كيف يمكن للمرء أن استخدام اباتشي mod_rewrite إلى حل نموذجي URL المستندة إلى المشاكل التي تواجه commonony المواقع. نعطي وصفا تفصيليا حول كيفية حل المشكلة عن طريق تكوين كل عنوان إعادة كتابة rulesets.



أباتشي خادم HTTP الإصدار 2.0 Up
مقدمة ل mod_rewrite

وحدة اباتشي mod_rewrite هو القاتل واحد، أي أنه هو وحدة متطورة حقا الذي يوفر وسيلة قوية للقيام التلاعب URL. مع ذلك يمكنك أن تفعل ما يقرب من جميع أنواع التلاعب URL هل حلمت عنه. سعر لديك لدفع هو قبول تعقيد، وذلك لأن mod_rewrite الصورة العيب الرئيسي هو أنه ليس من السهل فهم واستخدام للمبتدئين.وحتى الخبراء أحيانا أباتشي اكتشاف جوانب جديدة حيث mod_rewrite يمكن أن تساعد.
وبعبارة أخرى: مع mod_rewrite تبادل لاطلاق النار إما على نِفَسٌ ك في القدم للمرة الاولى وأبدا استخدامها مرة أخرى أو أحبها لبقية حياتك بسبب قوتها. هذه الورقة تحاول أن أعطيك بعض أحداث النجاح الأولي لتجنب الحالة الأولى من خلال تقديم حلول اخترع بالفعل لك.

أباتشي خادم HTTP الإصدار 2.0 Up
حلول عملية

يأتون إلى هنا الكثير من الحلول العملية لقد اخترع إما نِفَسٌ ي أو التي تم جمعها من حلول الآخرين في الماضي. لا تتردد في تعلم السحر الاسود من اعادة كتابة URL من هذه الأمثلة.

تنبيه: اعتمادا على تكوين الخادم الخاص بك، يمكن أن يكون من الضروري تغيير قليلا من الأمثلة عن الوضع الخاص بك، على سبيل المثال إضافة [PT]العلم عند استخدام وبالإضافة إلى ذلك mod_alias و mod_userdir إلخ، أو إعادة كتابة مجموعة الأوامر لتناسب في هتكس. السياق بدلا من الواحد خادم السياق. دائما في محاولة لفهم ما مجموعة الأوامر خاص فعلا قبل استخدامها. انه تجنب المشاكل.
أباتشي خادم HTTP الإصدار 2.0 Up
URL تخطيط

الكنسي عناوين المواقع

الوصف:في بعض مزودات الويب وهناك أكثر من عنوان لأحد الموارد. عادة ما تكون هناك عناوين الكنسي (التي ينبغي أن تستخدم في الواقع وتوزيعها)، وتلك التي هي مجرد اختصارات، منها الداخلية، الخ. المستقلة التي URL المستخدم المرفقة مع طلب انه يجب ان نرى في نهاية المطاف واحد الكنسي فقط.
الحل:نحن لا 1 HTTP إعادة توجيه خارجي لجميع عناوين المواقع غير المقبول لمعالجتها في وجهة النظر من موقع المتصفح وبالنسبة لجميع الطلبات اللاحقة. في المثال أدناه مجموعة الأوامر نستبدل ~ / المستخدم من قبل الكنسي المستخدم / ش / وتحديد خط مائل زائدة عن مفقود / ش / المستخدم .

RewriteRule ^ / ~ ([^ /] +) /؟ (*) / ش / $ 1 / $ 2 [ R ]
RewriteRule ^ / ([أويغه]) / ( [^ /] + ) $ $ / 1 / $ 2 / [ R ]
الكنسي أسماء المضيفين

الوصف:الهدف من هذه القاعدة لفرض استخدام اسم المضيف وجه الخصوص، وتفضيلها على غيرها من أسماء المضيفين التي يمكن استخدامها للوصول إلى الموقع نِفَسٌ ه.على سبيل المثال، إذا كنت ترغب في فرض استخدام www.example.com بدلا من example.com ، قد تستخدم متغير من هذه الوصفة.الحل:
# بالنسبة للمواقع التي تعمل على منفذ آخر من 80
٪ RewriteCond {HTTP_HOST}! ^ شبكة الاتصالات العالمية \. سبيل المثال \. com [NC]
٪ RewriteCond {HTTP_HOST}! ^ $
RewriteCond٪ {SERVER_PORT}! ^ 80 دولار
RewriteRule ^ / http://www.example.com (*): {٪ SERVER_PORT} / $ 1 [L، R]

# وبالنسبة لموقع يعمل على المنفذ 80
٪ RewriteCond {HTTP_HOST}! ^ شبكة الاتصالات العالمية \. سبيل المثال \. com [NC]
٪ RewriteCond {HTTP_HOST}! ^ $
RewriteRule ^ / (*) http://www.example.com/ $ 1 [L، R]
انتقل DocumentRoot

الوصف:وعادة ما DocumentRoot من خادم ويب تتصل مباشرة الى URL " / ". لكن غالبا ما تكون هذه البيانات ليست حقا من أعلى مستوى الأولوية، ربما كان مجرد كيان واحد من الكثير من برك البيانات. على سبيل المثال في مواقع الشبكة الداخلية لدينا هناك / ه / على شبكة الاتصالات العالمية /(الصفحة الرئيسية لWWW)، / ه / sww / (الصفحة الرئيسية لشبكة الإنترانت) وما إلى ذلك الآن لأن البيانات من DocumentRoot يبقى في / ه / على شبكة الاتصالات العالمية / كان لدينا للتأكد من أن جميع الصور inlined وغيرها من الاشياء داخل هذا العمل تجمع بيانات عن طلبات لاحقة.
الحل:نحن توجيه URL / إلى / ه / على شبكة الاتصالات العالمية / :

في RewriteEngine
RewriteRule ^ $ / / ه / على شبكة الاتصالات العالمية / [ R ]
لاحظ أن هذا يمكن أيضا أن يتم التعامل معها باستخدام RedirectMatch التوجيه:

RedirectMatch ^ / $ http://example.com/e/www/
زائدة مشكلة القطع

الوصف:ويمكن كل مسؤول الموقع الشبكي يغني أغنية عن مشكلة خط مائل زائدة على الدلائل المرجعية عناوين المواقع. اذا كانوا في عداد المفقودين، ومقالب الخادم خطأ، لأنه إذا كنت أقول ~ / quux / فو بدلا من / ~ quux / فو / ثم بحث خادم ل ملف اسمه فو . ولأن هذا الملف هو الدليل أنه يشكو. في الواقع فإنه يحاول اصلاحها نِفَسٌ ها في معظم الحالات، ولكن في بعض الأحيان هذه الآلية يجب أن يحتذى من قبل لك. على سبيل المثال بعد كنت قد فعلت الكثير من rewritings URL معقدة لنصوص CGI الخ.
الحل:الحل لهذه المشكلة خفية هو السماح للخادم بإضافة خط مائل زائدة تلقائيا. للقيام بذلك بشكل صحيح لدينا لاستخدام إعادة توجيه خارجي، وبالتالي فإن المتصفح تطلب بشكل صحيح الصور اللاحقة وما إذا نحن فقط لم إعادة كتابة الداخلية، وهذا لن ينجح الا لصفحة الدليل، ولكن سيكون على غير ما يرام عندما يتم تضمين أي الصور في هذه الصفحة مع عناوين URL النسبية، لأن من شأن المتصفح يطلب كائن في مبطنة. على سبيل المثال، طلب image.gif في ~ / quux / فو / index.html و ستصبح / ~ quux / image.gif دون توجيه خارجي!
لذلك، على أن تفعل هذه الخدعة نكتب:

في RewriteEngine
RewriteBase / ~ quux /
RewriteRule ^ فو $ فو / [ R ]
لا يمكن للمجنون وكسول القيام به حتى ما يلي في المستوى الأعلى هتكس. ملف من homedir بهم. لكن لاحظ أن هذا يخلق بعض النفقات العامة التجهيز.

في RewriteEngine
RewriteBase / ~ quux /
RewriteCond٪ {REQUEST_FILENAME} -D
RewriteRule ^ (. + [^ /] ) $ $ 1 / [R]
Webcluster من خلال تخطيط URL متجانس

الوصف:نحن نريد أن إنشاء تخطيط URL متجانسة ومتسقة على جميع خوادم الشبكة العالمية على webcluster الإنترانت، أي كل عناوين المواقع (في تعريف الخادم المحلي، وبالتالي يتوقف!) أصبح في الواقع خادم مستقل ! ما نريده هو اعطاء مساحة WWW متناسقة خادم مستقل التخطيط: لا URL يجب أن يكون لتشمل أي ملقم الهدف الصحيح بدنيا. وينبغي أن الكتلة نِفَسٌ ها تدفعنا تلقائيا إلى المضيف هدف مادي.
الحل:أولا، معرفة ملقمات الهدف يأتي من (الموزعة) خرائط الخارجية التي تحتوي على معلومات حيث المستخدمين والمجموعات والكيانات البقاء. ويكون على شكل

USER1 server_of_user1
user2 server_of_user2
::
وضعنا لهم في ملفات map.xxx إلى المضيف . ثانيا نحن بحاجة إلى توجيه كافة الملقمات لإعادة توجيه عناوين المواقع من الأشكال

/ ش / المستخدم / anypath
/ ز / مجموعة / anypath
/ ه / كيان / anypath
إلى

http://physical-host/u/user/anypath
http://physical-host/g/group/anypath
http://physical-host/e/entity/anypath
عندما URL غير صالحة محليا إلى ملقم. ومجموعة الأوامر التالية هل هذا بالنسبة لنا بمساعدة من الملفات خريطة (على افتراض أن server0 هو خادم الافتراضية التي سيتم استخدامها إذا كان المستخدم لا يوجد لديه دخول في الخريطة):

في RewriteEngine

RewriteMap المستخدم إلى مضيف TXT :/ الطريق / / map.user إلى مضيف
RewriteMap مجموعة إلى مضيف TXT :/ الطريق / / map.group إلى مضيف
RewriteMap كيان إلى مضيف TXT :/ الطريق / / map.entity إلى مضيف

RewriteRule ^ / ش / ([^ /] +) / http://؟ (*). $ {مستخدم إلى المضيف: 1 دولار | server0} / يو / $ 1/2 $
RewriteRule ^ / ز / ([^ /] +) / http://؟ (*). $ {مجموعة إلى المضيف: 1 دولار | server0} / ز / $ 1/2 $
RewriteRule ^ / E / ([^ /] +) / http://؟ (*). $ {كيان إلى المضيف: 1 دولار | server0} / ه / $ 1/2 $

RewriteRule ^ / ([أويغه]) / ([^ /] +) /؟ $ / $ 1 / $ 2/.www /
RewriteRule ^ / ([أويغه]) / ([^ /] +) / ([^] +. +) / $ 1 / $ 2/.www / $ 3 \
تحرك Homedirs إلى خادم الويب مختلفة

الوصف:وقد طلبت العديد من المواقع لإيجاد حل للوضع التالي: انهم يريدون فقط لإعادة توجيه جميع homedirs على خادم الويب إلى خادم ويب آخر. انهم عادة ما تحتاج مثل هذه الأمور عندما وضع أحدث مزود ويب الذي سيحل محل القديم مع مرور الوقت.
الحل:الحل هو تافه مع mod_rewrite . على الشبكة العالمية القديمة ونحن مجرد توجيه جميع ~ / المستخدم / anypath عناوين المواقع إلىhttp://newserver/ ~ المستخدم / anypath .

في RewriteEngine
RewriteRule ^ / ~ (. +) http:// newserver ~ / $ 1 [R، L]
منظم Homedirs

الوصف:بعض المواقع مع الآلاف من المستخدمين وعادة ما يستخدم تخطيط homedir منظم، أي كل homedir هو في دليل فرعي التي تبدأ على سبيل المثال مع الحرف الأول من اسم المستخدم. هكذا، ~ / فو / anypath هو / الوطن / و / فو / .www / anypath بينما ~ / شريط / anypath هو / الوطن / ب / شريط / .www / anypath .
الحل:نحن نستخدم مجموعة الأوامر التالية لتوسيع الروابط تيلدا إلى تخطيط بالضبط أعلاه.

في RewriteEngine
RewriteRule ^ / ~ ( ([ي]) [A-Z0-9] +) (*) / الوطن / $ 2 / $ $ 3 1/.www
الملفات إعادة التنظيم

الوصف:هذا هو حقا مثال فاضح: تطبيق القاتل الذي يستخدم بشكل كبير لكل دليل RewriteRules للحصول على نظرة على نحو سلس ويشعر على شبكة الانترنت في حين لم تطرق هيكلها البيانات أو تعديلها. خلفية: net.sw هو الأرشيف الخاص بي من حزم البرامج المتاحة مجانا يونيكس، والتي بدأت في جمع في عام 1992.هو على حد سواء لي هواية وعمل على ذلك، لأنه في حين أدرس علوم الكمبيوتر عملت أيضا لسنوات عديدة كنظام ومسؤول الشبكة في وقت فراغي. كل اسبوع انا بحاجة الى بعض النوع من البرامج لذلك أنا خلق تسلسل هرمي عميق من الدلائل حيث كنت تخزين الحزم:

drwxrwxr-X 2 اعضاء netsw 512 3 أغسطس 18:39 السمعية /
drwxrwxr-X 2 اعضاء netsw 512 9 يوليو 14:37 المعيار /
drwxrwxr-X 12 مستخدمين netsw 512 9 يوليو 00:34 تشفير /
drwxrwxr-X 5 مستخدمين netsw 512 9 يوليو 00:41 قاعدة البيانات /
drwxrwxr-X 4 اعضاء netsw 512 30 يوليو Dicts 19:25 /
drwxrwxr-X 10 مستخدمين netsw 512 9 يوليو 01:54 / الجرافيك
drwxrwxr-X 5 مستخدمين netsw 512 9 يوليو قراصنة 01:58 /
drwxrwxr-X 8 مستخدمين netsw 512 9 يوليو انفوسيس 03:19 /
drwxrwxr-X 3 اعضاء netsw 512 9 يوليو 03:21 رياضيات /
drwxrwxr-X 3 اعضاء netsw 512 9 يوليو 03:24 متفرقات /
drwxrwxr-X 9 مستخدمين netsw 512 1 أغسطس 16:33 شبكة /
drwxrwxr-X 2 اعضاء netsw 512 9 يوليو 05:53 مكتب /
drwxrwxr-X 7 مستخدمين netsw 512 9 يوليو 09:24 SoftEng /
drwxrwxr-X 7 مستخدمين netsw 512 9 يوليو 12:17 النظام /
drwxrwxr-X 12 مستخدمين netsw 512 3 أغسطس 20:15 صف الحروف /
drwxrwxr-X 10 مستخدمين netsw 512 9 يوليو X11 14:08 /
في تموز 1996 قررت أن تجعل من هذا الأرشيف العام إلى العالم عبر واجهة ويب لطيف. "لطيفة" يعني أنني أردت أن تقدم واجهة حيث يمكنك استعراض مباشرة من خلال التسلسل الهرمي للأرشيف. و "لطيفة" وسائل أنني لم يرغب في تغيير أي شيء داخل هذا التسلسل الهرمي - ولا حتى عن طريق وضع بعض نصوص CGI في الجزء العلوي منه. لماذا؟ لأنه يجب أن يكون فوق هيكل في وقت لاحق يمكن الوصول إليها عبر بروتوكول نقل الملفات كذلك، وأنا لا أريد أي ويب أو أشياء CGI أن تكون هناك.
الحل:الحل من جزأين: الأول هو مجموعة من نصوص CGI الذي خلق كل الصفحات على جميع المستويات دليل على ذبابة. أنا وضعت لهم تحت / ه / netsw / .www / على النحو التالي:

-RW-R - R - 1 المستخدمين netsw 1318 أغسطس 18:10 1 wwwacl
drwxr-XR-X 18 مستخدمين netsw 512 5 أغسطس 15:51 بيانات /
-RW-RW-RW-1 netsw المستخدمين 372982 5 أغسطس LOGFILE 16:35
-RW-R - R - 1 المستخدمين netsw 659 4 أغسطس 09:27 TODO
-RW-R - R - 1 المستخدمين netsw 1 أغسطس 5697 18:01 netsw-about.html
-rwxr-XR-× 1 المستخدمين netsw 579 2 أغسطس 10:33 netsw-access.pl
-rwxr-XR-× 1 المستخدمين netsw 1 أغسطس 1532 17:35 netsw-changes.cgi
-rwxr-XR-× 1 المستخدمين netsw 5 أغسطس 2866 14:49 netsw-home.cgi
drwxr-XR-X 2 اعضاء netsw 512 8 يوليو 23:47 netsw، IMG /
-rwxr-XR-× 1 المستخدمين netsw 24050 5 أغسطس 15:49 netsw-lsdir.cgi
-rwxr-XR-× 1 المستخدمين netsw 3 أغسطس 1589 18:43 netsw-search.cgi
-rwxr-XR-× 1 netsw المستخدمين 1 أغسطس 1885 17:41 netsw-tree.cgi
-RW-R - R - 1 المستخدمين netsw 234 30 يوليو 16:35 netsw-unlimit.lst
و البيانات / فرعي يحمل بنية الدليل أعلاه، أي الحقيقي net.sw الاشياء ويتم تحديثها تلقائيا عبر rdist من وقت لآخر. الجزء الثاني من المشكلة يبقى: كيفية ربط هذه الهياكل معا إلى شجرة واحدة على نحو سلس URL المظهر؟ نحن نريد لاخفاء البيانات / دليل من المستخدم أثناء تشغيل البرامج النصية CGI المناسبة لعناوين المواقع المختلفة. هنا هو الحل: أولا أضع التالية في ملف التكوين لكل دليل في DocumentRoot من خادم لاعادة كتابة URL أعلنت / net.sw / إلى مسار داخلي / ه / netsw :

RewriteRule ^ net.sw $ net.sw / [R]
RewriteRule ^ net.sw / (*) $ ه / netsw / 1 $
القاعدة الأولى هي للطلبات التي يغيب عن خط مائل زائدة! القاعدة الثانية يفعل الشيء الحقيقي. ويأتي بعد ذلك تكوين القاتل الذي يبقى في ملف التكوين لكل دليل / ه / netsw / .www / .wwwacl :

خيارات ExecCGI FollowSymLinks يتضمن MultiViews

في RewriteEngine

# وصلنا عن طريق / net.sw / بادئة
RewriteBase / net.sw /

# علينا أولا إعادة كتابة الجذر إلى دير
# النصي التعامل مع CGI
RewriteRule ^ $ netsw-home.cgi [L]
RewriteRule ^ مؤشر \. HTML $ netsw-home.cgi [L]

تجريد # خارج الدلائل الفرعية عندما
# طلبات متصفح لنا من صفحات perdir
RewriteRule ^. + / (netsw-[^ /] + / +) $ $ 1 [L]

# والآن كسر إعادة كتابة للملفات المحلية
RewriteRule ^ netsw المنزل \ CGI * - [L]
RewriteRule ^ netsw-التغييرات \ CGI * - [L]
RewriteRule ^ netsw في البحث عن \ CGI * - [L]
. RewriteRule ^ netsw شجرة \ CGI $ - [L]
. RewriteRule ^ netsw، حول \ HTML $ - [L]
RewriteRule ^ netsw، IMG / * $ - [L]

# أي شيء آخر هو الذي يحصل على التعامل مع subdir
# من جانب آخر نصي CGI
RewriteRule ^ netsw-lsdir \ CGI * -.. [C]
RewriteRule (*) netsw-lsdir.cgi / 1 $
بعض التلميحات لتفسير:

  1. لاحظ L (السابق) لا مجال العلم واستبدال (' - ') في الجزء الرابع
  2. لاحظ ! (لا) حرف و C (سلسلة) العلم في القاعدة الأولى في الجزء الأخير
  3. لاحظ التقاط كل نمط في الحكم مشاركة
NCSA imagemap إلى أباتشي mod_imap

الوصف:عند التبديل من خادم الويب NCSA إلى خادم الويب أباتشي أكثر حداثة الكثير من الناس يرغبون في الانتقال السلس. هكذا يريدون صفحات التي تستخدم القديمة NCSA imagemap برنامج للعمل تحت اباتشي مع الحديث mod_imap . المشكلة هي أن هناك الكثير من الارتباطات التشعبية حولها بإشارةimagemap البرنامج عن طريق / cgi-bin/imagemap/path/to/page.map . تحت أباتشي هذا لمجرد قراءة / الطريق / / page.map .
الحل:نحن نستخدم قاعدة عالمية لإزالة بادئة في ذبابة على لجميع الطلبات:

في RewriteEngine
RewriteRule ^ / cgi-bin/imagemap (*) $ 1 [PT]
البحث في صفحات أكثر من دليل واحد

الوصف:أحيانا يكون من الضروري السماح للبحث عن صفحات الشبكة العالمية في أكثر من دليل واحد. هنا يمكن MultiViews أو تقنيات أخرى لا يساعد.
الحل:نحن برمجة مجموعة الأوامر واضح وهو البحث عن الملفات في الدلائل.

في RewriteEngine

# أول محاولة للعثور عليه في العرف / ..
# ... وإذا وجدت توقف وتكون سعيدا:
RewriteCond / الخاص / docroot / dir1 /٪ {} REQUEST_FILENAME-F
RewriteRule ^ (. +) / الخاص / docroot / dir1 / $ 1 [L]

# 2 في محاولة للعثور عليه في حانة / ...
# ... وإذا وجدت توقف وتكون سعيدا:
RewriteCond / الخاص / docroot / dir2 /٪ {} REQUEST_FILENAME-F
RewriteRule ^ (. +) / الخاص / docroot / dir2 / $ 1 [L]

آخر # تستمر لالاسم المستعار أو غيرها من التوجيهات scriptalias التي،
# الخ.
RewriteRule ^ (+) - [PT]
تعيين متغيرات البيئة وفقا لأجزاء URL


الرجوع الى أعلى الصفحة اذهب الى الأسفل
apache
اعضاء فعالين
اعضاء فعالين
apache


عدد المشاركات : 123
نقاط : 227
التقيم : 20
تاريخ الميلاد : 15/03/1990
تاريخ التسجيل : 14/08/2012
العمر : 34

أباتشي خادم HTTP الإصدار 2.0 Empty
مُساهمةموضوع: رد: أباتشي خادم HTTP الإصدار 2.0   أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء أغسطس 14, 2012 9:59 am

RewriteRule ^ (+) - [PT]
تعيين متغيرات البيئة وفقا لأجزاء URL

الوصف:ربما كنت تريد أن تبقي معلومات الحالة بين الطلبات واستخدام عنوان URL لترميز عليه. ولكن كنت لا تريد استخدام مجمع CGI لكافة صفحات فقط لتجريد خارج هذه المعلومات.
الحل:نستخدم قاعدة إعادة الكتابة لتجريد خارج مركز المعلومات وتذكرها عن طريق متغير بيئة التي يمكن dereferenced في وقت لاحق من داخل XSSI أو CGI.هذه الطريقة URL / فو / S = جاوة / شريط / تحصل على ترجمتها إلى / فو / شريط / ومتغير البيئة يسمى حالة تم تعيين إلى القيمة "جافا".

في RewriteEngine
RewriteRule ^ / (*). S = ([^ /] +) / $ 1/3 $ [E = (*). تصريح: $ 2 ]
المضيفون العَضّوِ الظاهري

الوصف:افترض أنك تريد توفير شبكة الاتصالات العالمية. المستخدم . host.domain.com للموقع من المرور عبر DNS سجلات A فقط على نِفَسٌ الجهاز، ودون أي virtualhosts على هذا الجهاز.
الحل:لطلبات HTTP/1.0 لا يوجد حل، ولكن لHTTP/1.1 طلبات التي تحتوي على المضيف: HTTP رأس يمكننا استخدام مجموعة الأوامر التالية لإعادة كتابةhttp://www.username.host.com/anypath داخليا إلى / الوطن / المستخدم / anypath :

في RewriteEngine
RewriteCond٪ { HTTP_HOST } ^ شبكة الاتصالات العالمية \. [^] + \. المضيف \. com $
RewriteRule ^ (. +)٪ {HTTP_HOST} $ 1 [C]
RewriteRule ^ شبكة الاتصالات العالمية \. ([^] +) \. المضيف \. com (*) / الوطن / 1 $ $ 2
إعادة توجيه Homedirs للأجانب

الوصف:نحن نريد لإعادة توجيه عناوين المواقع homedir إلى آخر مزود الويب www.somewhere.com عندما يقوم المستخدم الطالبة لا يبقى في المجال المحليourdomain.com . ويستخدم أحيانا في سياقات هذا المضيف الظاهري.
الحل:مجرد إعادة كتابة الحالة:

في RewriteEngine
RewriteCond٪ {REMOTE_HOST} ! ^. + \. ourdomain \. com $
RewriteRule ^ (~ /. +) $ http://www.somewhere.com/ 1 [R، L]
وفي حالة عدم إعادة توجيه عناوين المواقع الأخرى على الويب

الوصف:هناك أسئلة وأجوبة نموذجية حول إعادة كتابة عنوان هو كيفية إعادة توجيه طلبات فشلها في خادم الويب من ألف إلى باء خادم الويب عادة ما يتم ذلك عن طريقErrorDocument نصوص CGI في بيرل، ولكن هناك أيضا mod_rewrite حل. ولكن لاحظت أن هذا يؤدي أكثر من سوء استخدامErrorDocument CGI-النصي!
الحل:الحل الأول لديه أفضل أداء ولكن أقل مرونة، وأقل خطأ آمنة:

في RewriteEngine
RewriteCond / الخاص / docroot /٪ {REQUEST_FILENAME} !-F
RewriteRule ^ (. +) http:// webserverB . دوم / 1 $
المشكلة هنا هي أن هذا لن ينجح الا لصفحات داخل DocumentRoot . في حين أن تتمكن من إضافة المزيد من الشروط (على سبيل المثال للتعامل مع homedirs أيضا، وغيرها) هناك أفضل البديل:

في RewriteEngine
٪ RewriteCond {REQUEST_URI} !-U
RewriteRule ^ (. +) http:// webserverB . دوم / 1 $
هذا يستخدم URL نظرة الاخضر ميزة من mod_rewrite . والنتيجة هي أن هذا سوف يعمل لجميع أنواع وعناوين المواقع هي وسيلة آمنة. ولكنه لا يفعل لها تأثير الأداء على الشبكة العالمية، وذلك لأن لكل طلب هناك واحد subrequest أكثر الداخلية. هكذا، إذا كان خادم الويب الخاص بك يعمل على وحدة المعالجة المركزية القوية، واستخدام هذه واحدة. إذا كان جهاز بطيء، واستخدام النهج الأول أو أفضل ErrorDocument CGI-النصي.
الموسعة إعادة توجيه

الوصف:أحيانا نحتاج إلى مزيد من التحكم (فيما يتعلق حرف الهروب آلية) من عناوين المواقع على الموجهات. وعادة ما URL حبات أباتشي وظيفة الهروب يهرب أيضا المراسي، أي عناوين مثل " مرساة # للتسجيل ". لا يمكنك استخدام هذا مباشرة على الموجهات مع mod_rewrite لأن uri_escape ()وظيفة من طراز أباتشي والهروب أيضا الطابع التجزئة. كيف يمكننا إعادة توجيه إلى URL من هذا القبيل؟
الحل:لدينا لاستخدام حل أهوج لمشكلة عن طريق استخدام برنامج نصي NPH-CGI الذي يقوم على إعادة توجيه نِفَسٌ ها. لأنه هنا يتم لا مفر (NPH = غير parseable الرؤوس). أولا نقدم مخطط URL جديد xredirect: من خلال ما يلي لكل خادم خط التكوين (يجب أن تكون واحدة من قواعد إعادة الكتابة الماضي):

RewriteRule ^ xredirect: (+) / الطريق / / NPH-xredirect.cgi / $ 1 \
[T = التطبيق / x-هتبد-CGI، L]
هذا يفرض على جميع عناوين المواقع مسبوقة مع xredirect: أن الأنابيب من خلال NPH-xredirect.cgi البرنامج. وهذا البرنامج يتطلع فقط مثل:

#! / الطريق / / بيرل
# #
# # NPH-xredirect.cgi - NPH / CGI سيناريو الموجهات الموسعة
# # حقوق الطبع والنشر (ج) 1997 رالف S. Engelschall، جميع الحقوق محفوظة.
# #

$ | = 1؛
$ $ والمفعلين ENV {'PATH_INFO "}؛

طباعة "HTTP/1.0 302 انتقل مؤقتا \ ن"؛
الطباعة "خادم: $ ENV {'SERVER_SOFTWARE'} \ ن"؛
طباعة "الموقع: $ URL \ ن"؛
طباعة "نوع المحتوى: نص / HTML \ ن"؛
طباعة "\ ن"؛
الطباعة "<HTML> \ ن"؛
الطباعة "<HEAD> \ ن"؛
طباعة "<TITLE> 302 انتقل مؤقتا (موسع) </ TITLE> \ ن"؛
الطباعة "</ رئيس> \ ن"؛
طباعة "<BODY> \ ن"؛
طباعة "<h1> تحليل انتقل مؤقتا (موسع) </ H1> \ ن"؛
طباعة "وثيقة انتقلت <a HREF="$url"> هنا </ a> <p> و\ ن"؛
الطباعة "</ BODY> \ ن"؛
الطباعة "</ HTML> \ ن"؛

# # # # EOF
هذا يوفر لك وظيفة للقيام الموجهات إلى جميع مخططات URL، أي بما في ذلك واحد والتي لا تقبل مباشرة بواسطة mod_rewrite . على سبيل المثال يمكنك الآن أيضا إعادة توجيه إلى الأخبار: أخبار عبر

RewriteRule ^ anyurl xredirect: الأخبار: أخبار

تنبيه: لديك عدم وضع [R] أو [R، L] لحكم أعلاه لأن xredirect: تحتاج إلى توسيعها في وقت لاحق من قبل وضعنا الخاص "من خلال أنبوب" القاعدة المذكورة أعلاه.الأرشيف وصول معدد

الوصف:هل تعرف CPAN عظيم (الشامل بيرل الأرشيف الشبكة) تحت http://www.perl.com/CPAN ؟ هذا لا إعادة توجيه إلى خوادم بروتوكول نقل الملفات واحدة من عدة في مختلف أنحاء العالم والتي تحمل مرآة CPAN وتقريبا بالقرب من موقع العميل الطالب. في الواقع يمكن أن تسمى هذه خدمة الوصول إلى بروتوكول نقل الملفات المتنوعة. في حين يدير CPAN عبر نصوص CGI، وكيف يمكن اتباع نهج مماثل ينفذ عن طريق mod_rewrite ؟
الحل:أول ما نلاحظه أن من الإصدار 3.0.0 mod_rewrite يمكن أيضا استخدام " FTP: "الخطة على الموجهات. والثانية، يمكن أن يتم تقريب الموقع من قبلRewriteMap على نطاق المستوى الأعلى للعميل. مع مجموعة الأوامر 1 بالسلاسل صعب يمكننا استخدام هذا المجال على مستوى عال كمفتاح لدينا خريطة مضاعفة.

في RewriteEngine
RewriteMap متعددة TXT :/ الطريق / / map.cxan
RewriteRule ^ / CxAN / (*)٪ {REMOTE_HOST} :: $ 1 [C]
RewriteRule ^ + \.. ([A-ZA-Z] +) :: {متعددة: $ $ (*). $ 1 | ftp.default.dom} $ 2 [R، L]

# #
الإرسال المتعدد خريطة لCxAN - # # map.cxan
# #

دي ftp://ftp.cxan.de/CxAN/
المملكة المتحدة ftp://ftp.cxan.uk/CxAN/
كوم ftp://ftp.cxan.com/CxAN/
:
# # # # EOF
الوقت التي تعتمد على إعادة كتابة

الوصف:عندما حيل مثل الوقت التي تعتمد على المحتوى يجب أن يحدث الكثير من المواقع لا تزال تستخدم نصوص CGI الذي القيام به لإعادة توجيه سبيل المثال إلى صفحات متخصصة. كيف يمكن أن يتم ذلك عن طريق mod_rewrite ؟
الحل:هناك الكثير من المتغيرات اسمه TIME_xxx لظروف إعادة كتابة. بالتزامن مع أنماط مقارنة lexicographic خاص <STRING ، > STRING و = STRING يمكننا القيام به وقت تعتمد على الموجهات:

في RewriteEngine
RewriteCond٪ {TIME_HOUR}٪ {TIME_MIN}> 0700
RewriteCond٪ {TIME_HOUR}٪ {TIME_MIN} <1900
RewriteRule ^ فو \. HTML $ foo.day.html
RewriteRule ^ فو \. HTML $ foo.night.html
وهذا يوفر محتوى foo.day.html تحت عنوان foo.html من 7:00 حتي 19:00 و في الوقت المتبقي محتويات foo.night.html .مجرد ميزة لطيفة للموقع ...
التوافق لYYYY إلى الهجرة XXXX

الوصف:كيف يمكننا جعل عناوين المواقع متوافقة مع الإصدارات السابقة (التي ما زالت موجودة تقريبا) بعد الهجرة document.YYYY إلى document.XXXX ، على سبيل المثال بعد ترجمة مجموعة من . أتش تي أم أل الملفات . phtml ؟
الحل:نحن مجرد كتابة الاسم إلى basename واختبار لوجود ملحق جديد. إذا كان موجودا، ونحن نأخذ بهذا الاسم، وإلا فإننا كتابة URL إلى حالته الأصلية.

# مجموعة الأوامر الى الوراء التوافق لل
إعادة كتابة # document.html إلى document.phtml
# عندما وفقط عندما document.phtml موجود
# ولكن لم يعد document.html
في RewriteEngine
RewriteBase / ~ quux /
تحليل # خارج basename، ولكن تذكر حقيقة
RewriteRule ^ \ HTML $ $ 1 [C، E = WasHTML: نعم] (*).
# لإعادة كتابة document.phtml إذا موجودا
RewriteCond٪ {REQUEST_FILENAME}. phtml-F
RewriteRule ^ (*) $ $ 1.phtml [S = 1]
# عكس آخر انقطاع basename السابقة
٪ RewriteCond {ENV: WasHTML} ^ نعم $
RewriteRule ^ (*) $ $ 1.html

أباتشي خادم HTTP الإصدار 2.0 Up
التعامل مع محتوى

من القديم إلى الجديد (المتدرب)

الوصف:نفترض أننا قمنا بتغيير اسم مؤخرا في الصفحة foo.html إلى bar.html وتريد الآن أن تقدم عنوان URL القديم من أجل التوافق. في الواقع نحن نريد أن مستخدمي URL القديم حتى لا يتعرف التي تمت إعادة تسمية الصفحات.
الحل:نعيد كتابة عنوان الموقع القديم إلى الجديد داخليا عن طريق القاعدة التالية:

في RewriteEngine
RewriteBase / ~ quux /
RewriteRule ^ فو \. HTML $ بار . HTML
من القديم إلى الجديد (خارجي)

الوصف:نفترض مرة أخرى بأننا قد أعيدت تسميته في الآونة الأخيرة في الصفحة foo.html إلى bar.html وتريد الآن أن تقدم عنوان URL القديم من أجل التوافق. ولكن هذه المرة نريد أن يحصل لمح مستخدمي URL القديم إلى الجديد، أي مجال عملهم الموقع متصفحات يجب تغيير أيضا.
الحل:نحن فرض إعادة توجيه HTTP إلى عنوان جديد الأمر الذي يؤدي إلى تغيير في برامج التصفح والاطلاع وبالتالي للمستخدمين:

في RewriteEngine
RewriteBase / ~ quux /
RewriteRule ^ فو \. HTML $ بار . أتش تي أم أل [ R ]
المتصفح المحتوى التابعة

الوصف:على الأقل لصفحات المستوى الأعلى هو مهم في بعض الأحيان اللازمة لتقديم الأمثل لمحتوى المتصفح تعتمد على أي أحد لديه لتوفير الحد الأقصى لإصدار المتغيرات آخر نتسكيب، إصدار الحد الأدنى للمتصفحات لينكس، ونسخة ميزة المتوسط ​​بالنسبة لجميع الآخرين .
الحل:لا يمكننا استخدام محتوى التفاوض لأن المتصفحات لا توفر نوعها في هذا النموذج. بدلا من ذلك علينا أن نعمل على رأس HTTP "وكيل المستخدم". وcondig التالية بما يلي: إذا كان رأس HTTP "عامل المستخدم" يبدأ ب "موزيلا / 3"، في الصفحة foo.html يتم إعادة كتابة ل foo.NS.html ووتتوقف إعادة كتابة. إذا كان المتصفح هو "لينكس" أو "موزيلا" من النسخة 1 أو 2 في URL يصبح foo.20.html . جميع المتصفحات الأخرى تتلقى صفحةfoo.32.html . يتم ذلك من قبل مجموعة الأوامر التالية:

RewriteCond٪ HTTP_USER_AGENT {} ^ موزيلا / 3 . *
RewriteRule ^ فو \. HTML $ فو. NS . أتش تي أم أل [ L ]

RewriteCond٪ HTTP_USER_AGENT {} ^ الوشق / . * [أو]
٪ RewriteCond {HTTP_USER_AGENT} ^ موزيلا / [12] . *
RewriteRule ^ فو \. HTML $ فو. 20 . أتش تي أم أل [ L ]

RewriteRule ^ فو \. HTML $ فو. 32 . أتش تي أم أل [ L ]
دينامية ميرور

الوصف:نفترض أن هناك صفحات الويب لطيفة على المضيفين البعيدين نريد ان نجلب إلى مساحة لدينا. للخوادم FTP ونستخدم مرآة البرنامج الذي يحافظ فعلا صريح يصل إلى تاريخ نسخة من بيانات الاستشعار عن بعد على الجهاز المحلي. للحصول على خادم الويب يمكن أن نستخدم برنامج webcopy الذي يعمل مماثلة عبر HTTP. لكن كلا من التقنيات لديها عيب واحد رئيسي: النسخة المحلية هو دائما مثلما حديثة إلى أنه في كثير من الأحيان نحن تشغيل البرنامج. سيكون من الأفضل بكثير إذا المرآة ليست ثابتة لدينا لإنشاء صراحة. بدلا من ذلك نحن نريد مرآة ديناميكي مع البيانات التي يتم تحديثها تلقائيا عند وجود حاجة (بيانات محدثة عن المضيف البعيد).
الحل:لتوفير هذه الميزة نحن تعيين صفحة ويب بعيد أو حتى webarea الكامل عن بعد لمساحة لدينا من خلال استخدام و المناولة وكيل ميزة (علم [ف] ):

في RewriteEngine
RewriteBase / ~ quux /
RewriteRule ^ hotsheet / (*) $ http://www.tstimpreso.com/hotsheet/ $ 1 [ ف ]

في RewriteEngine
RewriteBase / ~ quux /
RewriteRule ^ الولايات المتحدة الأمريكية، أخبار \. HTML $ http://www.quux-corp.com/news/index.html [ ف ]
عكس المرآة الحيوي

الوصف:...الحل:
في RewriteEngine
RewriteCond / مرآة / لعام / remotesite / $ 1-U
RewriteRule ^ http://www \. remotesite \. com / (*) $ / مرآة / لعام / remotesite / 1 $
استرجاع البيانات المفقودة من الشبكة الداخلية

الوصف:هذا هو وسيلة خادعة من تشغيل فعليا للشركات الإنترنت خادم الويب (خارجي) ( www.quux-corp.dom )، مع الحفاظ في الواقع والحفاظ على البيانات الخاصة به على خادم ويب إنترانت (الداخلية) ( www2.quux-corp.dom ) الذي هو محمي بواسطة جدار حماية. الخدعة هي أن على مزود ويب خارجي نحن استرداد البيانات المطلوبة عن ذبابة على واحد من الداخلية.
الحل:أولا، علينا أن نتأكد من أن جدار الحماية لدينا لا يزال يحمي خادم الويب الداخلي والذي يسمح فقط عن ويب خارجي لاسترجاع البيانات منه. لجدار الحماية علبة تصفية يمكننا على سبيل المثال تكوين مجموعة الأوامر جدار الحماية كما يلي:

تسمح المضيف www.quux-corp.dom ميناء> 1024 -> المضيف www2.quux-corp.dom ميناء 80
ينفون المضيف * ميناء * -> المضيف www2.quux-corp.dom ميناء 80
ضبط فقط على بناء الجملة الخاص التكوين الفعلي. الآن يمكن أن نقرر أن يكون mod_rewrite القواعد التي تطلب من البيانات الناقصة في الخلفية من خلال ميزة إنتاجية الوكيل:

RewriteRule ^ ~ / ([^ /] +) /؟ (*) / الوطن / $ 1/.www / 2 $
٪ RewriteCond {REQUEST_FILENAME} !-F
٪ RewriteCond {REQUEST_FILENAME} !-D
RewriteRule ^ / الوطن / ([^ /] +) / على شبكة الاتصالات العالمية /؟ (*) http:// www2 . quux-corp.dom / ~ $ 1/pub / $ 2 [ ف ]
موازنة التحميل

الوصف:لنفترض أننا نريد لتحميل موازنة حركة المرور إلى www.foo.com على شبكة الاتصالات العالمية [0-5] foo.com. (ما مجموعه 6 ملقمات). كيف يمكن القيام بذلك؟
الحل:هناك الكثير من الحلول الممكنة لهذه المشكلة. وسوف نناقش لأول مرة المعروف DNS المستندة إلى متغير ثم واحدة خاصة مع mod_rewrite :

  1. DNS ذهابا وروبنأبسط طريقة لتحقيق التوازن بين الحمل هي استخدام سلسلة متعاقبة من ميزة DNS BIND . هنا فقط يمكنك تكوين شبكة الاتصالات العالمية [0-9]. foo.com كالمعتاد في DNS الخاص بك مع السجلات (العنوان)، على سبيل المثال

    www0 IN A 1.2.3.1
    www1 IN A 1.2.3.2
    www2 IN A 1.2.3.3
    www3 IN A 1.2.3.4
    www4 IN A 1.2.3.5
    www5 IN A 1.2.3.6
    ثم أضفت وبالإضافة إلى ذلك الإدخال التالي:

    www في www0.foo.com CNAME.
    في www1.foo.com CNAME.
    في www2.foo.com CNAME.
    في www3.foo.com CNAME.
    في www4.foo.com CNAME.
    في www5.foo.com CNAME.
    في www6.foo.com CNAME.
    لاحظ أن هذا يبدو خطأ، ولكن هو في الواقع سمة المقصود من BIND ، ويمكن استخدامها في هذا السبيل. ومع ذلك، عند الآن www.foo.comيحصل على حلها، BIND يعطي مهلة www6-www0 - ولكن في كل مرة permutated قليلا / أمر استدارة. هذه الطريقة التي انتشرت العملاء على خوادم مختلفة. لكن لاحظ أن هذه ليست موازنة مثالية مخطط، وذلك لأن حل DNS معلومات يحصل مؤقتا من خوادم أخرى على الشبكة، وذلك مرة واحدة في العميل قد حل www.foo.com على وجه الخصوص wwwN.foo.com ، جميع الطلبات اللاحقة يذهب أيضا لهذا الاسم خاصةwwwN.foo.com . لكن النتيجة النهائية على ما يرام، لأن تنتشر حقا المبلغ الإجمالي للطلبات على مزودات الويب المختلفة.
  2. DNS موازنة التحميلA متطورة DNS المستندة إلى طريقة لتحقيق التوازن بين الحمل هي استخدام برنامج lbnamed التي يمكن العثور عليها فيhttp://www.stanford.edu/ ~ المخططين / مستندات / lbnamed / lbnamed.html . بل هو بيرل 5 برنامج بالاشتراك مع أدوات auxilliary الذي يوفر الحقيقي للموازنة التحميل DNS.
  3. وكيل المناولة ذهابا وروبنفي هذه الصيغة التي نستخدمها mod_rewrite ولها ميزة إنتاجية الوكيل. أولا علينا أن نكرس www0.foo.com أن تكون في الواقعwww.foo.com باستخدام واحد

    www في www0.foo.com CNAME.
    الدخول في DNS. ثم نقوم بتحويل www0.foo.com إلى خادم وكيل فقط، أي أننا تكوين هذا الجهاز بحيث يتم دفع فقط كل عناوين المواقع قادمة من خلال وكيل الداخلية لأحد الملقمات 5 أخرى ( www1-www5 ). لتحقيق ذلك علينا أولا إنشاء مجموعة الأوامر التي اتصالات السيناريو موازنةlb.pl لجميع عناوين المواقع.

    في RewriteEngine
    RewriteMap مسار PRG رطل :/ / إلى / lb.pl
    RewriteRule ^ / {رطل: $ $ $ (1)} (+). [P، L]
    ثم نكتب lb.pl :

    #! / الطريق / / بيرل
    # #
    # # lb.pl - موازنة النصي
    # #

    $ | = 1؛

    $ اسم = "على شبكة الاتصالات العالمية"؛ # قاعدة المضيف
    $ 1 = 1؛ # الخادم الأول (وليس 0 هنا، لأن 0 هو نِفَسٌ ي)
    $ مشاركة = 5؛ # خادم الماضي في الجولة روبن
    $ نطاق = "foo.dom"؛ # اسم المجال

    المركز الوطني للاستشعار $ = 0؛
    في حين أن (<STDIN>) {
    المركز الوطني للاستشعار $ = (($ المركز الوطني للاستشعار +1)٪ ($ مشاركة +1- دولار الأولى))؛
    $ = خادم sprintf ($، اسم، المركز الوطني للاستشعار $ + $ 1، $ المجال "د٪٪ S٪ S")؛
    طباعة على "http:// $ الخادم / $ _"؛
    }

    # # # # EOF

    إشعار آخر: ما الُفَائدَة من هذا؟ يبدو www0.foo.com لا يزال هو فوق طاقتها؟ وكان الجواب نعم، انها مثقلة، ولكن مع سهل طلبات الإنتاجية الوكيل، فقط! جميع مباحث أمن الدولة، CGI، ePerl، ويتم ذلك تماما وما إلى ذلك التجهيز على الأجهزة الأخرى. هذه هي النقطة الأساسية.
  4. الأجهزة TCP / ذهابا وروبنهناك حل الأجهزة المتوفرة، أيضا. سيسكو لديها الوحش دعا LocalDirector التي يقوم موازنة على مستوى TCP / IP. في الواقع هذا هو نوع من الدوائر بوابة مستوى أمام webcluster. إذا كان لديك ما يكفي من المال، وحقا في حاجة الى حل مع الأداء العالي، واستخدام هذه واحدة.
جديد من نوع MIME، خدمة جديدة

الوصف:على شبكة الانترنت وهناك الكثير من برامج CGI أنيق. لكن استخدامها مملة عادة، لذلك الكثير من المسؤول عن الموقع عدم استخدامها. حتى معالج العمل أباتشي وميزة لأنواع MIME-مناسبة فقط عندما برامج CGI لا تحتاج عناوين المواقع الخاصة (في الواقع PATH_INFO و QUERY_STRINGS ) ومدخلاتها.أولا، دعونا تكوين نوع ملف جديد مع ملحق . SCGI (لCGI آمن) والتي سيتم معالجتها من قبل شعبي cgiwrap البرنامج. المشكلة هنا هي أنه على سبيل المثال نستخدم تخطيط URL متجانسة (انظر أعلاه) ملف داخل homedirs المستخدم لديه عنوان / ش / المستخدم / فو / bar.scgi . لكنcgiwrap يحتاج URL في شكل ~ / المستخدم / فو / bar.scgi / . القاعدة التالية حل المشكلة:

RewriteRule ^ / [أويغه] / ([^ /] +) / \. على شبكة الاتصالات العالمية / (+) \. SCGI (*) ...
... / الداخلية / CGI / المستخدم / cgiwrap ~ / $ 1 2.scgi / $ $ 3 [NS، T = التطبيق / x-HTTP-CGI ]
أو نفترض أن لدينا بعض البرامج أكثر أنيق: wwwlog (الذي يعرض access.log ل URL الشجرة و wwwidx (الذي يمتد لمحة على الشجرة URL) لدينا لتوفير مساحة URL لهذه البرامج لأنهم يعرفون في أي منطقة كانت. يجب أن تتصرف على أساسها. لكن هذه عادة قبيحة، لأنها كل مرة لا يزال من المطلوب أن المناطق، أي عادة ما كنا تشغيل swwidx برنامج من ضمن / ش / المستخدم / فو / من خلال ارتباط تشعبي

/ الداخلية / CGI / المستخدم / swwidx؟ ط = / ش / المستخدم / فو /
الذي هو قبيح. لأننا يجب أن الثابت رمز على حد سواء في موقع منطقة و مكان CGI داخل الارتباط التشعبي. عندما يكون لدينا لاعادة تنظيم المنطقة، ونحن ننفق الكثير من الوقت في تغيير وصلات متعددة.
الحل:الحل هنا هو توفير شكل خاص URL جديد الأمر الذي يؤدي تلقائيا إلى الاحتجاج على CGI السليم. نحن تكوين ما يلي:

RewriteRule ^ / ([أويغه]) / ([^ /] +) (/؟ *) / \ * / داخلية / CGI / المستخدم / wwwidx؟ ط = / $ 1 / $ 2 $ 3 /
RewriteRule ^ / ([أويغه]) / ([^ /] +) (/ *؟):؟ السجل / داخلية / CGI / المستخدم / wwwlog F = / $ 1 / $ 2 $ 3
الآن الارتباط التشعبي للبحث في / ش / المستخدم / فو / يقرأ فقط

HREF = "*"
الذي يحصل داخليا تحول تلقائيا إلى

/ الداخلية / CGI / المستخدم / wwwidx؟ ط = / ش / المستخدم / فو /
الرجوع الى أعلى الصفحة اذهب الى الأسفل
apache
اعضاء فعالين
اعضاء فعالين
apache


عدد المشاركات : 123
نقاط : 227
التقيم : 20
تاريخ الميلاد : 15/03/1990
تاريخ التسجيل : 14/08/2012
العمر : 34

أباتشي خادم HTTP الإصدار 2.0 Empty
مُساهمةموضوع: رد: أباتشي خادم HTTP الإصدار 2.0   أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء أغسطس 14, 2012 10:01 am




/ المستخدم / wwwidx؟ ط = / ش / المستخدم / فو /
نِفَسٌ النهج يؤدي إلى الاحتجاج من أجل الوصول إلى برنامج CGI عندما سجل الارتباط التشعبي : سجل يعتاد.
من ثابت إلى حيوية

الوصف:كيف يمكننا تحويل صفحة ثابتة foo.html في متغير ديناميكي foo.cgi بطريقة سلسة، أي دون سابق إنذار من قبل المتصفح / المستخدم.
الحل:نحن مجرد كتابة عنوان الموقع إلى البرنامج النصي CGI، وإجبار من نوع MIME الصحيح حتى يحصل تشغيل حقا بأنها النصي، CGI. بهذه الطريقة طلب ل / ~ quux / foo.html داخليا يؤدي إلى الاحتجاج quux ~ / / foo.cgi .

في RewriteEngine
RewriteBase / ~ quux /
RewriteRule ^ فو \. HTML $ فو. CGI [T = التطبيق / x-هتبد-CGI ]
على ذبابة على المحتوى التجديد

الوصف:هنا تأتي ميزة مقصور على فئة معينة حقا: ديناميكيا ولكن صفحات خدم بشكل ثابت، وينبغي تسليم أي صفحات وصفحات ثابتة نقية (للقراءة من نظام الملفات ومرت للتو من خلال)، لكنها يجب أن تكون ديناميكيا بواسطة مزود الويب إذا مفقود. بهذه الطريقة يمكن أن يكون لديك CGI ولدت صفحات التي يتم تقديم بشكل ثابت ما لم يكن أحد (أو cronjob) يزيل محتويات ثابت. ثم يحصل على تحديث محتويات.
الحل:ويتم هذا من خلال مجموعة الأوامر التالية:
٪ RewriteCond {REQUEST_FILENAME} !-S
RewriteRule ^ صفحة \. HTML $ صفحة. CGI [T = التطبيق / x-هتبد-CGI، L]
هنا طلب page.html يؤدي إلى المدى الداخلي لمقابلة page.cgi إذا page.html ما زال مفقودا أو لديه باطل حجم الملف. الخدعة هنا هو أنpage.cgi هو السيناريو المعتاد الذي CGI (بالإضافة إلى ذلك إلى ل STDOUT ) كتب انتاجها إلى ملف page.html . بمجرد تشغيله، والخادم يرسل بيانات page.html . عندما يكون المسؤول عن الموقع يريد فرض تحديث محتويات، وقال انه يزيل فقط page.html (تتم عادة من قبل cronjob).
وثيقة مع Autorefresh

الوصف:لن يكون ذلك جميلا أثناء إنشاء صفحة ويب معقدة إذا كان webbrowser سيكون تلقائيا تحديث الصفحة في كل مرة نكتب نسخة جديدة من داخل محرر لدينا؟مستحيل؟
الحل:لا! نحن مجرد تجمع بين ميزة MIME متعددة الأجزاء، وميزة NPH خادم الويب وقوة التلاعب URL من mod_rewrite . أولا، نحن إنشاء URL ميزة جديدة: إضافة فقط : التحديث إلى أي رابط يؤدي إلى تحديث هذا في كل مرة يتم تحديثها على نظام الملفات.

RewriteRule ^ (/ [أويغه] / [^ /] + / *؟):؟ التحديث الداخلي / / CGI / اباتشى / NPH التحديث-F = 1 دولار
عندما نحن الآن مرجع URL

/ ش / فو / شريط / page.html: التحديث
وهذا يؤدي إلى الاحتجاج الداخلي للURL

/ الداخلية / CGI / اباتشى / NPH التحديث،؟ F = / ش / فو / شريط / page.html
الجزء الوحيد الناقص هو السيناريو NPH-CGI. على الرغم من أن المرء عادة ما يقول "تركت باعتبارها ممارسة للقارئ" ؛-) سأقدم هذا، أيضا.

#! / SW / بن / بيرل
# #
# # NPH-التحديث - NPH / CGI النصي لصفحات منعش السيارات
# # حقوق الطبع والنشر (ج) 1997 رالف S. Engelschall، جميع الحقوق محفوظة.
# #
$ | = 1؛

تقسيم # المتغير QUERY_STRING
@ = الانقسام زوجا (/ و /، $ ENV {'QUERY_STRING'})؛
foreach $ الزوج (@ أزواج) {
($ اسم، قيمة $) = تقسيم (/ = / $، الزوج)؛
$ اسم = ~ TR / ي / ي /؛
$ اسم = 'QS_ ". $ اسم؛
$ قيمة = ~ ق /٪ ([A-FA-F0-9] [A-FA-F0-9]) / حزمة ("C"، عرافة ($ 1)) / على سبيل المثال؛
EVAL "\ $ $ اسم = " $ قيمة \ ""؛
}
$ QS_s = 1 إذا دولار (QS_s مكافئ'')؛
$ QS_n = 3600 إذا دولار (QS_n مكافئ'')؛
إذا دولار (QS_f مكافئ'') {
طباعة "HTTP/1.0 200 OK \ ن"؛
طباعة "نوع المحتوى: نص / HTML \ ن \ ن"؛
طباعة "<B> خطأ </ B>: لا يوجد ملف معين \ ن"؛
خروج (0)؛
}
إذا (!-F $ QS_f) {
طباعة "HTTP/1.0 200 OK \ ن"؛
طباعة "نوع المحتوى: نص / HTML \ ن \ ن"؛
طباعة "<B> خطأ </ B>: ملف $ QS_f لم يتم العثور على \ ن"؛
خروج (0)؛
}

شبه print_http_headers_multipart_begin {
طباعة "HTTP/1.0 200 OK \ ن"؛
$ ملزمة = "ThisRandomString12345"؛
طباعة "محتوى من نوع: متعددة / X-مختلط استبدال؛ حدود = $ متجهة \ ن"؛
وprint_http_headers_multipart_next؛
}

شبه print_http_headers_multipart_next {
طباعة "\ ن - $ متجهة \ ن"؛
}

شبه print_http_headers_multipart_end {
طباعة "\ ن - $ محدد - \ ن"؛
}

شبه displayhtml {
المحلي ($ العازلة) = @ _؛
$ طول = ليون ($ العازلة)؛
طباعة "نوع المحتوى: نص / HTML \ ن"؛
الطباعة "المحتوى طول: $ لين \ ن \ ن"؛
طباعة $ العازلة؛
}

شبه readfile {
المحلي ($ ملف) = @ _؛
محلي (* FP، $ حجم، $ العازلة، $ بايت)؛
($ X، X $ $، خ، خ $ $، خ، خ $ $، س، $ حجم) = القانون الأساسي ($ ملف)؛
$ حجم = sprintf ("D٪"، $ حجم)؛
المفتوحة (اف ب، "<$ ملف")؛
$ بايت = sysread (اف ب، $ العازلة، $ حجم)؛
وثيقة (اف ب)؛
العودة دولار العازلة؛
}

$ العازلة = & readfile ($ QS_f)؛
وprint_http_headers_multipart_begin؛
وdisplayhtml ($ العازلة)؛

شبه mystat {
المحلي ($ ملف) = $ _ [0]؛
المحلي ($ الوقت)؛

($ X، X $ $، خ، خ $ $، خ، خ $ $، خ، خ $ $، س، mtime $) = القانون الأساسي ($ ملف)؛
العودة دولار mtime؛
}

$ mtimeL = & mystat ($ QS_f)؛
$ $ = mtime mtime؛
ل($ ن = 0؛ $ ن <$ QS_n؛ $ N + +) {
في حين (1) {
$ mtime = & mystat ($ QS_f)؛
إذا دولار (شمال شرق mtime mtimeL $) {
$ $ = mtimeL mtime؛
نوم (2)؛
$ العازلة = & readfile ($ QS_f)؛
وprint_http_headers_multipart_next؛
وdisplayhtml ($ العازلة)؛
النوم (5)؛
$ mtimeL = & mystat ($ QS_f)؛
الماضي؛
}
النوم ($ QS_s)؛
}
}

وprint_http_headers_multipart_end؛

خروج (0)؛

# # # # EOF
كتلة استضافة الظاهري

الوصف:و ميزة من نوع اباتشي هو لطيف وتعمل كبرى عندما يكون لديك فقط بضع عشرات المضيفين الظاهري. ولكن عندما كنت أحد مقدمي خدمات الانترنت ولها مئات من المضيفين الظاهري لتوفير هذه الميزة ليست هي الخيار الأفضل.
الحل:لتوفير هذه الميزة نحن تعيين صفحة ويب بعيد أو حتى webarea الكامل عن بعد لمساحة لدينا من خلال استخدام و المناولة وكيل ميزة (علم [ف] ):

# #
# # vhost.map
# #
www.vhost1.dom:80 / path/to/docroot/vhost1
www.vhost2.dom:80 / path/to/docroot/vhost2
:
www.vhostN.dom:80 / الطريق / / docroot / vhostN

# #
# # httpd.conf و
# #
:
# استخدام الكنسي الموجهات على اسم المضيف، الخ.
UseCanonicalName على

:
إضافة # المضيف الظاهري أمام بتنسيق CLF
CustomLog / الطريق / / access_log "٪ {VHOST} ه ح٪٪٪ ل ش ر٪ "٪ ص \ "٪ S٪> ب"
:

# تمكين المحرك إعادة كتابة في الخادم الرئيسي
في RewriteEngine

تعريف # خريطتين: لتحديد عنوان واحد والتي تعرف 1
# المضيفين الظاهرية المتوفرة مع المقابلة لها
DocumentRoot #.
RewriteMap كثافة العمليات الصغيرة: tolower
RewriteMap vhost مسار :/ TXT / إلى / vhost.map

# القيام به الآن الفعلي تعيين المضيف الظاهري
# عن طريق حكم واحد ضخمة ومعقدة:
#
# 1. تأكد من أننا لا خريطة للمواقع المشتركة
٪ RewriteCond {REQUEST_URI}! ^ / commonurl1 /. *
٪ RewriteCond {REQUEST_URI}! ^ / commonurl2 /. *
:
٪ RewriteCond {REQUEST_URI}! ^ / commonurlN /. *
#
# 2. تأكد لدينا رأس المضيف، وذلك لأن
# حاليا نهجنا يدعم فقط
# الظاهرية من خلال استضافة هذا الرأس
٪ RewriteCond {HTTP_HOST}! ^ $
#
# 3. صغيرة اسم المضيف
RewriteCond $ {صغيرة:٪ {HTTP_HOST} | لا شيء} (. +) ^ $
#
# 4. بحث في هذا المضيف وvhost.map
# تذكر انه فقط عندما يكون مسار
# (وليس "لا شيء" من أعلاه)
RewriteCond $ {vhost:٪ 1} ^ (/ *.) $
#
# 5. أخيرا يمكننا رسم خريطة للموقع الى موقع docroot لها
# وتذكر المضيف الظاهري للتسجيل puposes
RewriteRule ^ /٪ 1 $ / $ 1 [E = VHOST: $ {صغيرة:٪ {HTTP_HOST}}] (*).
:

أباتشي خادم HTTP الإصدار 2.0 Up
وصول تقييد

منع من الروبوتات

الوصف:كيف يمكننا منع الروبوت مزعج حقا من استرجاع صفحات webarea محددة؟ A / ملف robots.txt ملف يحتوي على مقالات من "بروتوكول استبعاد الروبوت" هي عادة ليست كافية للتخلص من مثل هذا الروبوت.
الحل:نحن نستخدم مجموعة الأوامر التي تحظر على عناوين المواقع على webarea ~ / فو / quux / قوس / (وربما في منطقة دليل عميق جدا فهرستها حيث اجتياز الروبوت من شأنه أن يخلق كبيرة حمولة الخادم). علينا أن نتأكد من أننا تمنع الوصول فقط إلى روبوت خاص، أي تحريم مجرد المضيف حيث يعمل الروبوت ليست كافية. وهذا من شأنه منع المستخدمين من هذا المضيف، أيضا. علينا أن ننجز هذا أيضا ما يناسبها من رأس HTTP عامل المستخدم معلومات.

RewriteCond٪ HTTP_USER_AGENT {} ^ NameOfBadRobot . *
٪ RewriteCond {REMOTE_ADDR} ^ 123 \ 0.45 \ 0.67 \. [8-9] $
RewriteRule ^ ~ / quux / فو / قوس / + -. [ F ]
منعت مضمنة صور

الوصف:نفترض لدينا تحت http://www.quux-corp.de/ ~ quux / بعض الصفحات التي تحتوي على رسومات GIF inlined. هذه الرسومات هي لطيفة، لذلك آخرون إدراج مباشرة لهم عن طريق وصلات إلى صفحاتهم. نحن لا نحب هذه الممارسة لأنها تضيف حركة عديمة الُفَائدَة إلى خادمنا.
الحل:في حين أننا لا نستطيع 100٪ حماية الصور من إدراج، يمكننا على الأقل تحد من الحالات التي يكون فيها المستعرض بإرسال رأس المرجعية HTTP.

RewriteCond٪ {HTTP_REFERER} ! ^ $
٪ RewriteCond {HTTP_REFERER}! ^ ~ http://www.quux-corp.de/ quux /. * $ [NC]
RewriteRule * \ GIF $.. - [F]

RewriteCond٪ {HTTP_REFERER}! ^ $
٪ RewriteCond {HTTP_REFERER}! * / فو، مع-GIF \. HTML $
RewriteRule . ^ inlined في وفو \ GIF $ - [F]
رفض استضافة

الوصف:كيف يمكننا منع قائمة من المضيفين تكوين خارجيا من استخدام الخادم لدينا؟
الحل:لأباتشي> = 1.3b6:

في RewriteEngine
RewriteMap المضيفين، تنكر TXT :/ الطريق / / hosts.deny
RewriteCond $ {المضيفين، تنكر:٪ {REMOTE_HOST} | لا وجدت} = لا وجدت [أو]!
RewriteCond $! {المضيفين، تنكر:٪ {REMOTE_ADDR} | لا وجدت} = لا وجدت
RewriteRule ^ / * - [F]
لأباتشي <= 1.3b6:

في RewriteEngine
RewriteMap المضيفين، تنكر TXT :/ الطريق / / hosts.deny
RewriteRule ^ / $ $ {المضيفين، تنكر:٪ {REMOTE_HOST} | لا وجدت} (*) / 1 $
RewriteRule ^ لا وجدت / * -. [F]
RewriteRule ^ لا وجدت / (*) $ $ {المضيفين، تنكر:٪ {REMOTE_ADDR} | لا وجدت} / 1 $
RewriteRule ^ لا وجدت / * -. [F]
RewriteRule ^ لا وجدت / (*) $ / $ 1

# #
# # hosts.deny
# #
# # انتبه! هذا هو عبارة عن خريطة، ليست قائمة، وحتى عندما وكيفية التعامل معها على هذا النحو.
# # mod_rewrite بتوزيع ذلك لأزواج مفتاح / قيمة، وذلك ما لا يقل عن
# # قيمة وهمية "-" يجب أن تكون موجودة في كل دخول.
# #

193.102.180.41 -
bsdti1.sdm.de -
192.76.162.40 -
رفض وكيل

الوصف:كيف يمكننا منع مجموعة معينة أو حتى للمستخدم من مجموعة خاصة من استخدام الوكيل أباتشي؟
الحل:علينا أولا أن نتأكد من mod_rewrite أقل (!) mod_proxy في ملف التكوين عند ترجمة من مزود ويب اباتشي. وبهذه الطريقة يحصل يطلق عليه قبلmod_proxy . ثم نحن تكوين ما يلي لمنع المضيفة التي تعتمد على ...

٪ RewriteCond {REMOTE_HOST} ^ badhost \. mydomain \. com $
RewriteRule ^ http:// [^ /.] \ mydomain.com * -.. [F]
(...) وهذه واحدة للمستخدم @ المضيفة التي تعتمد على إنكار:

٪ RewriteCond {REMOTE_IDENT} {@٪ REMOTE_HOST} ^ @ badguy badhost \. mydomain \. com $
RewriteRule ^ http:// [^ /.] \ mydomain.com * -.. [F]
خاص مصادقة البديل

الوصف:أحيانا هناك حاجة لمصادقة خاصة جدا، على سبيل المثال مصادقة والذي يتحقق لمجموعة من المستخدمين تكوين بشكل صريح. إلا أن هذه تلقي الوصول وبدون واضح مما دفع (والتي قد تحدث عند استخدام المصادقة الأساسية عبر mod_auth ).
الحل:نستخدم قائمة شروط إعادة كتابة لاستبعاد كل ما عدا أصدقائنا:

٪ RewriteCond {} REMOTE_IDENT٪ @ {REMOTE_HOST} ! ^ friend1@client1.quux-corp \. com $
RewriteCond٪ {REMOTE_IDENT} {@٪ REMOTE_HOST} ! ^ friend2 @ client2.quux-كورب \. com $
٪ RewriteCond {REMOTE_IDENT} {@٪ REMOTE_HOST} ! ^ friend3 @ client3.quux-كورب \. com $
RewriteRule ^ ~ / quux / فقط مقابل أصدقاء / - [F]
المرجعية المستندة إلى عاكس

الوصف:كيف يمكننا أن تبرمج عاكس URL مرن الذي يعمل على رأس "المرجعية" HTTP ويمكن تهيئتها مع العديد من الصفحات على انها تشير كما نحب؟
الحل:استخدام مجموعة الأوامر التالية صعبة حقا ...

RewriteMap مسار منحرف :/ TXT / إلى / deflector.map

٪ RewriteCond {HTTP_REFERER}! = ""
RewriteCond $ {منحرف:٪ {HTTP_REFERER}} ^ - $
RewriteRule ^ *٪ {HTTP_REFERER} [R، L]

٪ RewriteCond {HTTP_REFERER}! = ""
RewriteCond $! {منحرف:٪ {HTTP_REFERER} | لا وجدت} = لا وجدت
RewriteRule ^ * $ {منحرف:٪ {HTTP_REFERER}}. [R، L]
... بالتزامن مع خريطة إعادة كتابة المقابلة:

# #
# # deflector.map
# #

http://www.badguys.com/bad/index.html -
http://www.badguys.com/bad/index2.html -
http://www.badguys.com/bad/index3.html http://somewhere.com/
هذه التحويلات تلقائيا مرة أخرى طلب إلى صفحة في اشارة (عندما " - "يتم استخدام القيمة في الخريطة) أو على موقع محدد (عندما يتم تحديد عنوان URL في الخريطة كما الوسيطة الثانية).

أباتشي خادم HTTP الإصدار 2.0 Up
آخر

الخارجية المحرك إعادة كتابة

الوصف:هناك أسئلة وأجوبة: كيف يمكننا حل فو / بار / QUUX / الخ. المشكلة؟ ولا يبدو ان هناك حل عن طريق استخدام mod_rewrite ...
الحل:استخدام خارجي RewriteMap ، أي برنامج الذي يعمل بمثابة RewriteMap . يتم تشغيله مرة واحدة عند بدء التشغيل من نوع اباتشي يتلقى عناوين المواقع المطلوبة في STDIN ولها لوضع الناتج (إعادة كتابة عادة) URL على STDOUT (النظام نِفَسٌ ه!).

في RewriteEngine
RewriteMap quux خارطة PRG: / الطريق / / map.quux.pl
RewriteRule ^ ~ / quux / $ / ~ quux / (*). $ {quux خارطة: $ 1}

#! / الطريق / / بيرل

تعطيل # مخزنة I / O والذي من شأنه أن يؤدي
# لdeadloops لخادم أباتشي
$ | = 1؛

# قراءة عناوين سطر واحد لكل من وستدين
# توليد URL الاستبدال في STDOUT
في حين أن (<>) {
ق | ^ فو / | بار / |؛
طباعة $ _؛
}
هذا هو مثال مظاهرة فقط ويعيد كتابة كل عناوين المواقع فقط ~ / quux / فو / ... إلى / ~ quux / شريط / ... . في الواقع يمكنك برمجة ما تريد. إلا أن نلاحظ أنه في حين يمكن أن مثل هذه الخرائط تستخدم أيضا من قبل المستخدم العادي، فقط المسؤول عن النظام يمكن تحديد ذلك.

اللغات المتاحة: EN | كو

حقوق الطبع والنشر 2011 مؤسسة البرمجيات أباتشي.
مرخص تحت رخصة أباتشي، الإصدار 2.0
الرجوع الى أعلى الصفحة اذهب الى الأسفل
apache
اعضاء فعالين
اعضاء فعالين
apache


عدد المشاركات : 123
نقاط : 227
التقيم : 20
تاريخ الميلاد : 15/03/1990
تاريخ التسجيل : 14/08/2012
العمر : 34

أباتشي خادم HTTP الإصدار 2.0 Empty
مُساهمةموضوع: Apache > HTTP Server > Documentation > Version 2.0 > Miscellaneous Documentation Please note This document refers to the 2.0 version of Apache httpd, which is no longer recommended. If you are using    أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء أغسطس 14, 2012 10:03 am


Apache > HTTP Server > Documentation > Version 2.0 > Miscellaneous Documentation
Please note
This document refers to the 2.0 version of Apache httpd, which is no longer recommended.
If you are using the current versions of httpd (2.2 or 2.4), please visit their documentations instead:
Apache HTTP Server 2.2 documentation
Apache HTTP Server 2.4 documentation
You may follow this link to go to the 2.2 version of this document.
URL Rewriting Guide
Available Languages: en | ko
Originally written by
Ralf S. Engelschall <rse@apache.org>
December 1997
This document supplements the mod_rewrite reference documentation. It describes how one can use Apache's mod_rewrite to solve typical URL-based problems with which webmasters are commonony confronted. We give detailed descriptions on how to solve each problem by configuring URL rewriting rulesets.

Introduction to mod_rewrite
Practical Solutions
URL Layout
Content Handling
Access Restriction
Other

Introduction to mod_rewrite

The Apache module mod_rewrite is a killer one, i.e. it is a really sophisticated module which provides a powerful way to do URL manipulations. With it you can do nearly all types of URL manipulations you ever dreamed about. The price you have to pay is to accept complexity, because mod_rewrite's major drawback is that it is not easy to understand and use for the beginner. And even Apache experts sometimes discover new aspects where mod_rewrite can help.

In other words: With mod_rewrite you either shoot yourself in the foot the first time and never use it again or love it for the rest of your life because of its power. This paper tries to give you a few initial success events to avoid the first case by presenting already invented solutions to you.


Practical Solutions

Here come a lot of practical solutions I've either invented myself or collected from other people's solutions in the past. Feel free to learn the black magic of URL rewriting from these examples.

ATTENTION: Depending on your server-configuration it can be necessary to slightly change the examples for your situation, e.g. adding the [PT] flag when additionally using mod_alias and mod_userdir, etc. Or rewriting a ruleset to fit in .htaccess context instead of per-server context. Always try to understand what a particular ruleset really does before you use it. It avoid problems.

URL Layout

Canonical URLs
Description:
On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent of which URL the user supplied with the request he should finally see the canonical one only.

Solution:
We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and fix a missing trailing slash for /u/user.

RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]
Canonical Hostnames
Description:
The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of example.com, you might use a variant of the following recipe.
Solution:
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
Moved DocumentRoot
Description:
Usually the DocumentRoot of the webserver directly relates to the URL "/". But often this data is not really of top-level priority, it is perhaps just one entity of a lot of data pools. For instance at our Intranet sites there are /e/www/ (the homepage for WWW), /e/sww/ (the homepage for the Intranet) etc. Now because the data of the DocumentRoot stays at /e/www/ we had to make sure that all inlined images and other stuff inside this data pool work for subsequent requests.

Solution:
We redirect the URL / to /e/www/:

RewriteEngine on
RewriteRule ^/$ /e/www/ [R]
Note that this can also be handled using the RedirectMatch directive:

RedirectMatch ^/$ http://example.com/e/www/
Trailing Slash Problem
Description:
Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then the server searches for a file named foo. And because this file is a directory it complains. Actually it tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For instance after you have done a lot of complicated URL rewritings to CGI scripts etc.

Solution:
The solution to this subtle problem is to let the server add the trailing slash automatically. To do this correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If we only did a internal rewrite, this would only work for the directory page, but would go wrong when any images are included into this page with relative URLs, because the browser would request an in-lined object. For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the external redirect!

So, to do this trick we write:

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]
The crazy and lazy can even do the following in the top-level .htaccess file of their homedir. But notice that this creates some processing overhead.

RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
Webcluster through Homogeneous URL Layout
Description:
We want to create a homogeneous and consistent URL layout over all WWW servers on a Intranet webcluster, i.e. all URLs (per definition server local and thus server dependent!) become actually server independent! What we want is to give the WWW namespace a consistent server-independent layout: no URL should have to include any physically correct target server. The cluster itself should drive us automatically to the physical target host.

Solution:
First, the knowledge of the target servers come from (distributed) external maps which contain information where our users, groups and entities stay. The have the form

user1 server_of_user1
user2 server_of_user2
: :
We put them into files map.xxx-to-host. Second we need to instruct all servers to redirect URLs of the forms

/u/user/anypath
/g/group/anypath
/e/entity/anypath
to

http://physical-host/u/user/anypath
http://physical-host/g/group/anypath
http://physical-host/e/entity/anypath
when the URL is not locally valid to a server. The following ruleset does this for us by the help of the map files (assuming that server0 is a default server which will be used if a user has no entry in the map):

RewriteEngine on

RewriteMap user-to-host txt:/path/to/map.user-to-host
RewriteMap group-to-host txt:/path/to/map.group-to-host
RewriteMap entity-to-host txt:/path/to/map.entity-to-host

RewriteRule ^/u/([^/]+)/?(.*) http://${user-to-host:$1|server0}/u/$1/$2
RewriteRule ^/g/([^/]+)/?(.*) http://${group-to-host:$1|server0}/g/$1/$2
RewriteRule ^/e/([^/]+)/?(.*) http://${entity-to-host:$1|server0}/e/$1/$2

RewriteRule ^/([uge])/([^/]+)/?$ /$1/$2/.www/
RewriteRule ^/([uge])/([^/]+)/([^.]+.+) /$1/$2/.www/$3\
Move Homedirs to Different Webserver
Description:
Many webmasters have asked for a solution to the following situation: They wanted to redirect just all homedirs on a webserver to another webserver. They usually need such things when establishing a newer webserver which will replace the old one over time.

Solution:
The solution is trivial with mod_rewrite. On the old webserver we just redirect all /~user/anypath URLs to http://newserver/~user/anypath.

RewriteEngine on
RewriteRule ^/~(.+) http://newserver/~$1 [R,L]
Structured Homedirs
Description:
Some sites with thousands of users usually use a structured homedir layout, i.e. each homedir is in a subdirectory which begins for instance with the first character of the username. So, /~foo/anypath is /home/f/foo/.www/anypath while /~bar/anypath is /home/b/bar/.www/anypath.

Solution:
We use the following ruleset to expand the tilde URLs into exactly the above layout.

RewriteEngine on
RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3
Filesystem Reorganization
Description:
This really is a hardcore example: a killer application which heavily uses per-directory RewriteRules to get a smooth look and feel on the Web while its data structure is never touched or adjusted. Background: net.sw is my archive of freely available Unix software packages, which I started to collect in 1992. It is both my hobby and job to to this, because while I'm studying computer science I have also worked for many years as a system and network administrator in my spare time. Every week I need some sort of software so I created a deep hierarchy of directories where I stored the packages:

drwxrwxr-x 2 netsw users 512 Aug 3 18:39 Audio/
drwxrwxr-x 2 netsw users 512 Jul 9 14:37 Benchmark/
drwxrwxr-x 12 netsw users 512 Jul 9 00:34 Crypto/
drwxrwxr-x 5 netsw users 512 Jul 9 00:41 Database/
drwxrwxr-x 4 netsw users 512 Jul 30 19:25 Dicts/
drwxrwxr-x 10 netsw users 512 Jul 9 01:54 Graphic/
drwxrwxr-x 5 netsw users 512 Jul 9 01:58 Hackers/
drwxrwxr-x 8 netsw users 512 Jul 9 03:19 InfoSys/
drwxrwxr-x 3 netsw users 512 Jul 9 03:21 Math/
drwxrwxr-x 3 netsw users 512 Jul 9 03:24 Misc/
drwxrwxr-x 9 netsw users 512 Aug 1 16:33 Network/
drwxrwxr-x 2 netsw users 512 Jul 9 05:53 Office/
drwxrwxr-x 7 netsw users 512 Jul 9 09:24 SoftEng/
drwxrwxr-x 7 netsw users 512 Jul 9 12:17 System/
drwxrwxr-x 12 netsw users 512 Aug 3 20:15 Typesetting/
drwxrwxr-x 10 netsw users 512 Jul 9 14:08 X11/
In July 1996 I decided to make this archive public to the world via a nice Web interface. "Nice" means that I wanted to offer an interface where you can browse directly through the archive hierarchy. And "nice" means that I didn't wanted to change anything inside this hierarchy - not even by putting some CGI scripts at the top of it. Why? Because the above structure should be later accessible via FTP as well, and I didn't want any Web or CGI stuff to be there.

Solution:
The solution has two parts: The first is a set of CGI scripts which create all the pages at all directory levels on-the-fly. I put them under /e/netsw/.www/ as follows:

-rw-r--r-- 1 netsw users 1318 Aug 1 18:10 .wwwacl
drwxr-xr-x 18 netsw users 512 Aug 5 15:51 DATA/
-rw-rw-rw- 1 netsw users 372982 Aug 5 16:35 LOGFILE
-rw-r--r-- 1 netsw users 659 Aug 4 09:27 TODO
-rw-r--r-- 1 netsw users 5697 Aug 1 18:01 netsw-about.html
-rwxr-xr-x 1 netsw users 579 Aug 2 10:33 netsw-access.pl
-rwxr-xr-x 1 netsw users 1532 Aug 1 17:35 netsw-changes.cgi
-rwxr-xr-x 1 netsw users 2866 Aug 5 14:49 netsw-home.cgi
drwxr-xr-x 2 netsw users 512 Jul 8 23:47 netsw-img/
-rwxr-xr-x 1 netsw users 24050 Aug 5 15:49 netsw-lsdir.cgi
-rwxr-xr-x 1 netsw users 1589 Aug 3 18:43 netsw-search.cgi
-rwxr-xr-x 1 netsw users 1885 Aug 1 17:41 netsw-tree.cgi
-rw-r--r-- 1 netsw users 234 Jul 30 16:35 netsw-unlimit.lst
The DATA/ subdirectory holds the above directory structure, i.e. the real net.sw stuff and gets automatically updated via rdist from time to time. The second part of the problem remains: how to link these two structures together into one smooth-looking URL tree? We want to hide the DATA/ directory from the user while running the appropriate CGI scripts for the various URLs. Here is the solution: first I put the following into the per-directory configuration file in the DocumentRoot of the server to rewrite the announced URL /net.sw/ to the internal path /e/netsw:

RewriteRule ^net.sw$ net.sw/ [R]
RewriteRule ^net.sw/(.*)$ e/netsw/$1
The first rule is for requests which miss the trailing slash! The second rule does the real thing. And then comes the killer configuration which stays in the per-directory config file /e/netsw/.www/.wwwacl:

Options ExecCGI FollowSymLinks Includes MultiViews

RewriteEngine on

# we are reached via /net.sw/ prefix
RewriteBase /net.sw/

# first we rewrite the root dir to
# the handling cgi script
RewriteRule ^$ netsw-home.cgi [L]
RewriteRule ^index\.html$ netsw-home.cgi [L]

# strip out the subdirs when
# the browser requests us from perdir pages
RewriteRule ^.+/(netsw-[^/]+/.+)$ $1 [L]

# and now break the rewriting for local files
RewriteRule ^netsw-home\.cgi.* - [L]
RewriteRule ^netsw-changes\.cgi.* - [L]
RewriteRule ^netsw-search\.cgi.* - [L]
RewriteRule ^netsw-tree\.cgi$ - [L]
RewriteRule ^netsw-about\.html$ - [L]
RewriteRule ^netsw-img/.*$ - [L]

# anything else is a subdir which gets handled
# by another cgi script
RewriteRule !^netsw-lsdir\.cgi.* - [C]
RewriteRule (.*) netsw-lsdir.cgi/$1
Some hints for interpretation:

Notice the L (last) flag and no substitution field ('-') in the forth part
Notice the ! (not) character and the C (chain) flag at the first rule in the last part
Notice the catch-all pattern in the last rule
NCSA imagemap to Apache mod_imap
Description:
When switching from the NCSA webserver to the more modern Apache webserver a lot of people want a smooth transition. So they want pages which use their old NCSA imagemap program to work under Apache with the modern mod_imap. The problem is that there are a lot of hyperlinks around which reference the imagemap program via /cgi-bin/imagemap/path/to/page.map. Under Apache this has to read just /path/to/page.map.

Solution:
We use a global rule to remove the prefix on-the-fly for all requests:

RewriteEngine on
RewriteRule ^/cgi-bin/imagemap(.*) $1 [PT]
Search pages in more than one directory
Description:
Sometimes it is necessary to let the webserver search for pages in more than one directory. Here MultiViews or other techniques cannot help.

Solution:
We program a explicit ruleset which searches for the files in the directories.

RewriteEngine on

# first try to find it in custom/...
# ...and if found stop and be happy:
RewriteCond /your/docroot/dir1/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir1/$1 [L]

# second try to find it in pub/...
# ...and if found stop and be happy:
RewriteCond /your/docroot/dir2/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir2/$1 [L]

# else go on for other Alias or ScriptAlias directives,
# etc.
RewriteRule ^(.+) - [PT]
Set Environment Variables According To URL Parts
Description:
Perhaps you want to keep status information between requests and use the URL to encode it. But you don't want to use a CGI wrapper for all pages just to strip out this information.

Solution:
We use a rewrite rule to strip out the status information and remember it via an environment variable which can be later dereferenced from within XSSI or CGI. This way a URL /foo/S=java/bar/ gets translated to /foo/bar/ and the environment variable named STATUS is set to the value "java".

RewriteEngine on
RewriteRule ^(.*)/S=([^/]+)/(.*) $1/$3 [E=STATUS:$2]
Virtual User Hosts
Description:
Assume that you want to provide www.username.host.domain.com for the homepage of username via just DNS A records to the same machine and without any virtualhosts on this machine.

Solution:
For HTTP/1.0 requests there is no solution, but for HTTP/1.1 requests which contain a Host: HTTP header we can use the following ruleset to rewrite http://www.username.host.com/anypath internally to /home/username/anypath:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
Redirect Homedirs For Foreigners
Description:
We want to redirect homedir URLs to another webserver www.somewhere.com when the requesting user does not stay in the local domain ourdomain.com. This is sometimes used in virtual host contexts.

Solution:
Just a rewrite condition:

RewriteEngine on
RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$
RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L]
Redirect Failing URLs To Other Webserver
Description:
A typical FAQ about URL rewriting is how to redirect failing requests on webserver A to webserver B. Usually this is done via ErrorDocument CGI-scripts in Perl, but there is also a mod_rewrite solution. But notice that this performs more poorly than using an ErrorDocument CGI-script!

Solution:
The first solution has the best performance but less flexibility, and is less error safe:

RewriteEngine on
RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule ^(.+) http://webserverB.dom/$1
The problem here is that this will only work for pages inside the DocumentRoot. While you can add more Conditions (for instance to also handle homedirs, etc.) there is better variant:

RewriteEngine on
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.+) http://webserverB.dom/$1
This uses the URL look-ahead feature of mod_rewrite. The result is that this will work for all types of URLs and is a safe way. But it does a performance impact on the webserver, because for every request there is one more internal subrequest. So, if your webserver runs on a powerful CPU, use this one. If it is a slow machine, use the first approach or better a ErrorDocument CGI-script.

Extended Redirection
Description:
Sometimes we need more control (concerning the character escaping mechanism) of URLs on redirects. Usually the Apache kernels URL escape function also escapes anchors, i.e. URLs like "url#anchor". You cannot use this directly on redirects with mod_rewrite because the uri_escape() function of Apache would also escape the hash character. How can we redirect to such a URL?

Solution:
We have to use a kludge by the use of a NPH-CGI script which does the redirect itself. Because here no escaping is done (NPH=non-parseable headers). First we introduce a new URL scheme xredirect: by the following per-server config-line (should be one of the last rewrite rules):

RewriteRule ^xredirect:(.+) /path/to/nph-xredirect.cgi/$1 \
[T=application/x-httpd-cgi,L]
This forces all URLs prefixed with xredirect: to be piped through the nph-xredirect.cgi program. And this program just looks like:

#!/path/to/perl
##
## nph-xredirect.cgi -- NPH/CGI script for extended redirects
## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
##

$| = 1;
$url = $ENV{'PATH_INFO'};

print "HTTP/1.0 302 Moved Temporarily\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n";
print "Location: $url\n";
print "Content-type: text/html\n";
print "\n";
print "<html>\n";
print "<head>\n";
print "<title>302 Moved Temporarily (EXTENDED)</title>\n";
print "</head>\n";
print "<body>\n";
print "<h1>Moved Temporarily (EXTENDED)</h1>\n";
print "The document has moved <a HREF=\"$url\">here</a>.<p>\n";
print "</body>\n";
print "</html>\n";

##EOF##
This provides you with the functionality to do redirects to all URL schemes, i.e. including the one which are not directly accepted by mod_rewrite. For instance you can now also redirect to news:newsgroup via

RewriteRule ^anyurl xredirect:news:newsgroup
Notice: You have not to put [R] or [R,L] to the above rule because the xredirect: need to be expanded later by our special "pipe through" rule above.
Archive Access Multiplexer
Description:
Do you know the great CPAN (Comprehensive Perl Archive Network) under http://www.perl.com/CPAN? This does a redirect to one of several FTP servers around the world which carry a CPAN mirror and is approximately near the location of the requesting client. Actually this can be called an FTP access multiplexing service. While CPAN runs via CGI scripts, how can a similar approach implemented via mod_rewrite?

Solution:
First we notice that from version 3.0.0 mod_rewrite can also use the "ftp:" scheme on redirects. And second, the location approximation can be done by a RewriteMap over the top-level domain of the client. With a tricky chained ruleset we can use this top-level domain as a key to our multiplexing map.

RewriteEngine on
RewriteMap multiplex txt:/path/to/map.cxan
RewriteRule ^/CxAN/(.*) %{REMOTE_HOST}::$1 [C]
RewriteRule ^.+\.([a-zA-Z]+):Sad.*)$ ${multiplex:$1|ftp.default.dom}$2 [R,L]
##
## map.cxan -- Multiplexing Map for CxAN
##

de ftp://ftp.cxan.de/CxAN/
uk ftp://ftp.cxan.uk/CxAN/
com ftp://ftp.cxan.com/CxAN/
:
##EOF##
Time-Dependent Rewriting
Description:
When tricks like time-dependent content should happen a lot of webmasters still use CGI scripts which do for instance redirects to specialized pages. How can it be done via mod_rewrite?

Solution:
There are a lot of variables named TIME_xxx for rewrite conditions. In conjunction with the special lexicographic comparison patterns <STRING, >STRING and =STRING we can do time-dependent redirects:

RewriteEngine on
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
RewriteRule ^foo\.html$ foo.day.html
RewriteRule ^foo\.html$ foo.night.html
This provides the content of foo.day.html under the URL foo.html from 07:00-19:00 and at the remaining time the contents of foo.night.html. Just a nice feature for a homepage...

Backward Compatibility for YYYY to XXXX migration
Description:
How can we make URLs backward compatible (still existing virtually) after migrating document.YYYY to document.XXXX, e.g. after translating a bunch of .html files to .phtml?

Solution:
We just rewrite the name to its basename and test for existence of the new extension. If it exists, we take that name, else we rewrite the URL to its original state.

# backward compatibility ruleset for
# rewriting document.html to document.phtml
# when and only when document.phtml exists
# but no longer document.html
RewriteEngine on
RewriteBase /~quux/
# parse out basename, but remember the fact
RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
# rewrite to document.phtml if exists
RewriteCond %{REQUEST_FILENAME}.phtml -f
RewriteRule ^(.*)$ $1.phtml [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html

Content Handling

From Old to New (intern)
Description:
Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility. Actually we want that users of the old URL even not recognize that the pages was renamed.

Solution:
We rewrite the old URL to the new one internally via the following rule:

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo\.html$ bar.html
From Old to New (extern)
Description:
Assume again that we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility. But this time we want that the users of the old URL get hinted to the new one, i.e. their browsers Location field should change, too.

Solution:
We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view:

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo\.html$ bar.html [R]
Browser Dependent Content
Description:
At least for important top-level pages it is sometimes necessary to provide the optimum of browser dependent content, i.e. one has to provide a maximum version for the latest Netscape variants, a minimum version for the Lynx browsers and a average feature version for all others.

Solution:
We cannot use content negotiation because the browsers do not provide their type in that form. Instead we have to act on the HTTP header "User-Agent". The following condig does the following: If the HTTP header "User-Agent" begins with "Mozilla/3", the page foo.html is rewritten to foo.NS.html and and the rewriting stops. If the browser is "Lynx" or "Mozilla" of version 1 or 2 the URL becomes foo.20.html. All other browsers receive page foo.32.html. This is done by the following ruleset:

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
RewriteRule ^foo\.html$ foo.NS.html [L]

RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*
RewriteRule ^foo\.html$ foo.20.html [L]

RewriteRule ^foo\.html$ foo.32.html [L]
Dynamic Mirror
Description:
Assume there are nice webpages on remote hosts we want to bring into our namespace. For FTP servers we would use the mirror program which actually maintains an explicit up-to-date copy of the remote data on the local machine. For a webserver we could use the program webcopy which acts similar via HTTP. But both techniques have one major drawback: The local copy is always just as up-to-date as often we run the program. It would be much better if the mirror is not a static one we have to establish explicitly. Instead we want a dynamic mirror with data which gets updated automatically when there is need (updated data on the remote host).

Solution:
To provide this feature we map the remote webpage or even the complete remote webarea to our namespace by the use of the Proxy Throughput feature (flag [P]):

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^hotsheet/(.*)$ http://www.tstimpreso.com/hotsheet/$1 [P]
RewriteEngine on
RewriteBase /~quux/
RewriteRule ^usa-news\.html$ http://www.quux-corp.com/news/index.html [P]
Reverse Dynamic Mirror
Description:
...
Solution:
RewriteEngine on
RewriteCond /mirror/of/remotesite/$1 -U
RewriteRule ^http://www\.remotesite\.com/(.*)$ /mirror/of/remotesite/$1
Retrieve Missing Data from Intranet
Description:
This is a tricky way of virtually running a corporate (external) Internet webserver (www.quux-corp.dom), while actually keeping and maintaining its data on a (internal) Intranet webserver (www2.quux-corp.dom) which is protected by a firewall. The trick is that on the external webserver we retrieve the requested data on-the-fly from the internal one.

Solution:
First, we have to make sure that our firewall still protects the internal webserver and that only the external webserver is allowed to retrieve data from it. For a packet-filtering firewall we could for instance configure a firewall ruleset like the following:

ALLOW Host www.quux-corp.dom Port >1024 --> Host www2.quux-corp.dom Port 80
DENY Host * Port * --> Host www2.quux-corp.dom Port 80
Just adjust it to your actual configuration syntax. Now we can establish the mod_rewrite rules which request the missing data in the background through the proxy throughput feature:

RewriteRule ^/~([^/]+)/?(.*) /home/$1/.www/$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/home/([^/]+)/.www/?(.*) http://www2.quux-corp.dom/~$1/pub/$2 [P]
Load Balancing
Description:
Suppose we want to load balance the traffic to www.foo.com over www[0-5].foo.com (a total of 6 servers). How can this be done?

Solution:
There are a lot of possible solutions for this problem. We will discuss first a commonly known DNS-based variant and then the special one with mod_rewrite:

DNS Round-Robin
The simplest method for load-balancing is to use the DNS round-robin feature of BIND. Here you just configure www[0-9].foo.com as usual in your DNS with A(address) records, e.g.

www0 IN A 1.2.3.1
www1 IN A 1.2.3.2
www2 IN A 1.2.3.3
www3 IN A 1.2.3.4
www4 IN A 1.2.3.5
www5 IN A 1.2.3.6
Then you additionally add the following entry:

www IN CNAME www0.foo.com.
IN CNAME www1.foo.com.
IN CNAME www2.foo.com.
IN CNAME www3.foo.com.
IN CNAME www4.foo.com.
IN CNAME www5.foo.com.
IN CNAME www6.foo.com.
Notice that this seems wrong, but is actually an intended feature of BIND and can be used in this way. However, now when www.foo.com gets resolved, BIND gives out www0-www6 - but in a slightly permutated/rotated order every time. This way the clients are spread over the various servers. But notice that this not a perfect load balancing scheme, because DNS resolve information gets cached by the other nameservers on the net, so once a client has resolved www.foo.com to a particular wwwN.foo.com, all subsequent requests also go to this particular name wwwN.foo.com. But the final result is ok, because the total sum of the requests are really spread over the various webservers.

DNS Load-Balancing
A sophisticated DNS-based method for load-balancing is to use the program lbnamed which can be found at http://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html. It is a Perl 5 program in conjunction with auxilliary tools which provides a real load-balancing for DNS.

Proxy Throughput Round-Robin
In this variant we use mod_rewrite and its proxy throughput feature. First we dedicate www0.foo.com to be actually www.foo.com by using a single

www IN CNAME www0.foo.com.
entry in the DNS. Then we convert www0.foo.com to a proxy-only server, i.e. we configure this machine so all arriving URLs are just pushed through the internal proxy to one of the 5 other servers (www1-www5). To accomplish this we first establish a ruleset which contacts a load balancing script lb.pl for all URLs.

RewriteEngine on
RewriteMap lb prg:/path/to/lb.pl
RewriteRule ^/(.+)$ ${lb:$1} [P,L]
Then we write lb.pl:

#!/path/to/perl
##
## lb.pl -- load balancing script
##

$| = 1;

$name = "www"; # the hostname base
$first = 1; # the first server (not 0 here, because 0 is myself)
$last = 5; # the last server in the round-robin
$domain = "foo.dom"; # the domainname

$cnt = 0;
while (<STDIN>) {
$cnt = (($cnt+1) % ($last+1-$first));
$server = sprintf("%s%d.%s", $name, $cnt+$first, $domain);
print "http://$server/$_";
}

##EOF##
A last notice: Why is this useful? Seems like www0.foo.com still is overloaded? The answer is yes, it is overloaded, but with plain proxy throughput requests, only! All SSI, CGI, ePerl, etc. processing is completely done on the other machines. This is the essential point.
Hardware/TCP Round-Robin
There is a hardware solution available, too. Cisco has a beast called LocalDirector which does a load balancing at the TCP/IP level. Actually this is some sort of a circuit level gateway in front of a webcluster. If you have enough money and really need a solution with high performance, use this one.

New MIME-type, New Service
Description:
On the net there are a lot of nifty CGI programs. But their usage is usually boring, so a lot of webmaster don't use them. Even Apache's Action handler feature for MIME-types is only appropriate when the CGI programs don't need special URLs (actually PATH_INFO and QUERY_STRINGS) as their input. First, let us configure a new file type with extension .scgi (for secure CGI) which will be processed by the popular cgiwrap program. The problem here is that for instance we use a Homogeneous URL Layout (see above) a file inside the user homedirs has the URL /u/user/foo/bar.scgi. But cgiwrap needs the URL in the form /~user/foo/bar.scgi/. The following rule solves the problem:

RewriteRule ^/[uge]/([^/]+)/\.www/(.+)\.scgi(.*) ...
... /internal/cgi/user/cgiwrap/~$1/$2.scgi$3 [NS,T=application/x-http-cgi]
Or assume we have some more nifty programs: wwwlog (which displays the access.log for a URL subtree and wwwidx (which runs Glimpse on a URL subtree). We have to provide the URL area to these programs so they know on which area they have to act on. But usually this ugly, because they are all the times still requested from that areas, i.e. typically we would run the swwidx program from within /u/user/foo/ via hyperlink to

/internal/cgi/user/swwidx?i=/u/user/foo/
which is ugly. Because we have to hard-code both the location of the area and the location of the CGI inside the hyperlink. When we have to reorganize the area, we spend a lot of time changing the various hyperlinks.

Solution:
The solution here is to provide a special new URL format which automatically leads to the proper CGI invocation. We configure the following:

RewriteRule ^/([uge])/([^/]+)(/?.*)/\* /internal/cgi/user/wwwidx?i=/$1/$2$3/
RewriteRule ^/([uge])/([^/]+)(/?.*):log /internal/cgi/user/wwwlog?f=/$1/$2$3
Now the hyperlink to search at /u/user/foo/ reads only

HREF="*"
which internally gets automatically transformed to

/internal/cgi/user/wwwidx?i=/u/user/foo/
The same approach leads to an invocation for the access log CGI program when the hyperlink :log gets used.

From Static to Dynamic
Description:
How can we transform a static page foo.html into a dynamic variant foo.cgi in a seamless way, i.e. without notice by the browser/user.

Solution:
We just rewrite the URL to the CGI-script and force the correct MIME-type so it gets really run as a CGI-script. This way a request to /~quux/foo.html internally leads to the invocation of /~quux/foo.cgi.

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi]
On-the-fly Content-Regeneration
Description:
Here comes a really esoteric feature: Dynamically generated but statically served pages, i.e. pages should be delivered as pure static pages (read from the filesystem and just passed through), but they have to be generated dynamically by the webserver if missing. This way you can have CGI-generated pages which are statically served unless one (or a cronjob) removes the static contents. Then the contents gets refreshed.

Solution:
This is done via the following ruleset:
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^page\.html$ page.cgi [T=application/x-httpd-cgi,L]
Here a request to page.html leads to a internal run of a corresponding page.cgi if page.html is still missing or has filesize null. The trick here is that page.cgi is a usual CGI script which (additionally to its STDOUT) writes its output to the file page.html. Once it was run, the server sends out the data of page.html. When the webmaster wants to force a refresh the contents, he just removes page.html (usually done by a cronjob).

Document With Autorefresh
Description:
Wouldn't it be nice while creating a complex webpage if the webbrowser would automatically refresh the page every time we write a new version from within our editor? Impossible?

Solution:
No! We just combine the MIME multipart feature, the webserver NPH feature and the URL manipulation power of mod_rewrite. First, we establish a new URL feature: Adding just :refresh to any URL causes this to be refreshed every time it gets updated on the filesystem.

RewriteRule ^(/[uge]/[^/]+/?.*):refresh /internal/cgi/apache/nph-refresh?f=$1
Now when we reference the URL

/u/foo/bar/page.html:refresh
this leads to the internal invocation of the URL

/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
The only missing part is the NPH-CGI script. Although one would usually say "left as an exercise to the reader" ;-) I will provide this, too.

#!/sw/bin/perl
##
## nph-refresh -- NPH/CGI script for auto refreshing pages
## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
##
$| = 1;

# split the QUERY_STRING variable
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/A-Z/a-z/;
$name = 'QS_' . $name;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
eval "\$$name = \"$value\"";
}
$QS_s = 1 if ($QS_s eq '');
$QS_n = 3600 if ($QS_n eq '');
if ($QS_f eq '') {
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
print "<b>ERROR</b>: No file given\n";
exit(0);
}
if (! -f $QS_f) {
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
print "<b>ERROR</b>: File $QS_f not found\n";
exit(0);
}

sub print_http_headers_multipart_begin {
print "HTTP/1.0 200 OK\n";
$bound = "ThisRandomString12345";
print "Content-type: multipart/x-mixed-replace;boundary=$bound\n";
&print_http_headers_multipart_next;
}

sub print_http_headers_multipart_next {
print "\n--$bound\n";
}

sub print_http_headers_multipart_end {
print "\n--$bound--\n";
}

sub displayhtml {
local($buffer) = @_;
$len = length($buffer);
print "Content-type: text/html\n";
print "Content-length: $len\n\n";
print $buffer;
}

sub readfile {
local($file) = @_;
local(*FP, $size, $buffer, $bytes);
($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
$size = sprintf("%d", $size);
open(FP, "<$file");
$bytes = sysread(FP, $buffer, $size);
close(FP);
return $buffer;
}

$buffer = &readfile($QS_f);
&print_http_headers_multipart_begin;
&displayhtml($buffer);

sub mystat {
local($file) = $_[0];
local($time);

($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
return $mtime;
}

$mtimeL = &mystat($QS_f);
$mtime = $mtime;
for ($n = 0; $n < $QS_n; $n++) {
while (1) {
$mtime = &mystat($QS_f);
if ($mtime ne $mtimeL) {
$mtimeL = $mtime;
sleep(2);
$buffer = &readfile($QS_f);
&print_http_headers_multipart_next;
&displayhtml($buffer);
sleep(5);
$mtimeL = &mystat($QS_f);
last;
}
sleep($QS_s);
}
}

&print_http_headers_multipart_end;

exit(0);

##EOF##
Mass Virtual Hosting
Description:
The <VirtualHost> feature of Apache is nice and works great when you just have a few dozens virtual hosts. But when you are an ISP and have hundreds of virtual hosts to provide this feature is not the best choice.

Solution:
To provide this feature we map the remote webpage or even the complete remote webarea to our namespace by the use of the Proxy Throughput feature (flag [P]):

##
## vhost.map
##
www.vhost1.dom:80 /path/to/docroot/vhost1
www.vhost2.dom:80 /path/to/docroot/vhost2
:
www.vhostN.dom:80 /path/to/docroot/vhostN
##
## httpd.conf
##
:
# use the canonical hostname on redirects, etc.
UseCanonicalName on

:
# add the virtual host in front of the CLF-format
CustomLog /path/to/access_log "%{VHOST}e %h %l %u %t \"%r\" %>s %b"
:

# enable the rewriting engine in the main server
RewriteEngine on

# define two maps: one for fixing the URL and one which defines
# the available virtual hosts with their corresponding
# DocumentRoot.
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/path/to/vhost.map

# Now do the actual virtual host mapping
# via a huge and complicated single rule:
#
# 1. make sure we don't map for common locations
RewriteCond %{REQUEST_URI} !^/commonurl1/.*
RewriteCond %{REQUEST_URI} !^/commonurl2/.*
:
RewriteCond %{REQUEST_URI} !^/commonurlN/.*
#
# 2. make sure we have a Host header, because
# currently our approach only supports
# virtual hosting through this header
RewriteCond %{HTTP_HOST} !^$
#
# 3. lowercase the hostname
RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$
#
# 4. lookup this hostname in vhost.map and
# remember it only when it is a path
# (and not "NONE" from above)
RewriteCond ${vhost:%1} ^(/.*)$
#
# 5. finally we can map the URL to its docroot location
# and remember the virtual host for logging puposes
RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]
:

Access Restriction

Blocking of Robots
Description:
How can we block a really annoying robot from retrieving pages of a specific webarea? A /robots.txt file containing entries of the "Robot Exclusion Protocol" is typically not enough to get rid of such a robot.

Solution:
We use a ruleset which forbids the URLs of the webarea /~quux/foo/arc/ (perhaps a very deep directory indexed area where the robot traversal would create big server load). We have to make sure that we forbid access only to the particular robot, i.e. just forbidding the host where the robot runs is not enough. This would block users from this host, too. We accomplish this by also matching the User-Agent HTTP header information.

RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$
RewriteRule ^/~quux/foo/arc/.+ - [F]
Blocked Inline-Images
Description:
Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because it adds useless traffic to our server.

Solution:
While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser sends a HTTP Referer header.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
RewriteRule .*\.gif$ - [F]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$
RewriteRule ^inlined-in-foo\.gif$ - [F]
Host Deny
Description:
How can we forbid a list of externally configured hosts from using our server?

Solution:
For Apache >= 1.3b6:

RewriteEngine on
RewriteMap hosts-deny txt:/path/to/hosts.deny
RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^/.* - [F]
For Apache <= 1.3b6:

RewriteEngine on
RewriteMap hosts-deny txt:/path/to/hosts.deny
RewriteRule ^/(.*)$ ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND}/$1
RewriteRule !^NOT-FOUND/.* - [F]
RewriteRule ^NOT-FOUND/(.*)$ ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND}/$1
RewriteRule !^NOT-FOUND/.* - [F]
RewriteRule ^NOT-FOUND/(.*)$ /$1
##
## hosts.deny
##
## ATTENTION! This is a map, not a list, even when we treat it as such.
## mod_rewrite parses it for key/value pairs, so at least a
## dummy value "-" must be present for each entry.
##

193.102.180.41 -
bsdti1.sdm.de -
192.76.162.40 -
Proxy Deny
Description:
How can we forbid a certain host or even a user of a special host from using the Apache proxy?

Solution:
We first have to make sure mod_rewrite is below(!) mod_proxy in the Configuration file when compiling the Apache webserver. This way it gets called before mod_proxy. Then we configure the following for a host-dependent deny...

RewriteCond %{REMOTE_HOST} ^badhost\.mydomain\.com$
RewriteRule !^http://[^/.]\.mydomain.com.* - [F]
...and this one for a user@host-dependent deny:

RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} ^badguy@badhost\.mydomain\.com$
RewriteRule !^http://[^/.]\.mydomain.com.* - [F]
Special Authentication Variant
Description:
Sometimes a very special authentication is needed, for instance a authentication which checks for a set of explicitly configured users. Only these should receive access and without explicit prompting (which would occur when using the Basic Auth via mod_auth).

Solution:
We use a list of rewrite conditions to exclude all except our friends:

RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend1@client1.quux-corp\.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend2@client2.quux-corp\.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend3@client3.quux-corp\.com$
RewriteRule ^/~quux/only-for-friends/ - [F]
Referer-based Deflector
Description:
How can we program a flexible URL Deflector which acts on the "Referer" HTTP header and can be configured with as many referring pages as we like?

Solution:
Use the following really tricky ruleset...

RewriteMap deflector txt:/path/to/deflector.map

RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${deflector:%{HTTP_REFERER}} ^-$
RewriteRule ^.* %{HTTP_REFERER} [R,L]

RewriteCond %{HTTP_REFERER} !=""
RewriteCond ${deflector:%{HTTP_REFERER}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^.* ${deflector:%{HTTP_REFERER}} [R,L]
... in conjunction with a corresponding rewrite map:

##
## deflector.map
##

http://www.badguys.com/bad/index.html -
http://www.badguys.com/bad/index2.html -
http://www.badguys.com/bad/index3.html http://somewhere.com/
This automatically redirects the request back to the referring page (when "-" is used as the value in the map) or to a specific URL (when an URL is specified in the map as the second argument).


Other

External Rewriting Engine
Description:
A FAQ: How can we solve the FOO/BAR/QUUX/etc. problem? There seems no solution by the use of mod_rewrite...

Solution:
Use an external RewriteMap, i.e. a program which acts like a RewriteMap. It is run once on startup of Apache receives the requested URLs on STDIN and has to put the resulting (usually rewritten) URL on STDOUT (same order!).

RewriteEngine on
RewriteMap quux-map prg:/path/to/map.quux.pl
RewriteRule ^/~quux/(.*)$ /~quux/${quux-map:$1}
#!/path/to/perl

# disable buffered I/O which would lead
# to deadloops for the Apache server
$| = 1;

# read URLs one per line from stdin and
# generate substitution URL on stdout
while (<>) {
s|^foo/|bar/|;
print $_;
}
This is a demonstration-only example and just rewrites all URLs /~quux/foo/... to /~quux/bar/.... Actually you can program whatever you like. But notice that while such maps can be used also by an average user, only the system administrator can define it.

Available Languages: en | ko
الرجوع الى أعلى الصفحة اذهب الى الأسفل
 
أباتشي خادم HTTP الإصدار 2.0
الرجوع الى أعلى الصفحة 
صفحة 1 من اصل 1
 مواضيع مماثلة
-
» اخر اخبار مؤسسة أباتشي
» ما هي الخطط المستقبلية لهتبد أباتشي؟
» لماذا لا يمكنني نشر إلى خادم اباتشي بي باستخدام وضعت على الذهب نتسكيب وغيرها من البرامج؟
» اضف موقعك لـ 150 محرك بحث بضغطة زر واحدة http://onlinealley.com
»  اهداف مباراة الاردن و سنغافورة 11/10/2011 - مشاهدة اهداف مباراة المنتخب الاردني و سنغافورة 11/10/2011 نبض الشارع: http://jordanian.hooxs.com/t1997-topic#ixzz23NxCmQYT

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
موقع بوابة بلاد الشام ،belad-alsham :: lkj]dhj fgh] hgahl :: منتديات الشام بلادي :: منتدي الربح من الإنترنت Make Money From The InterNet :: منتدى أباتشي google.com Apache ،Binding-
انتقل الى:  
دخول
اسم العضو:
كلمة السر:
ادخلني بشكل آلي عند زيارتي مرة اخرى: 
:: لقد نسيت كلمة السر
تبادل اعلاني

مساحة اعلانية
مواقع صديقة
Feedage.com RSS
Feedage Grade B rated
!-- Feedage.com RSS Feed Tracking
Preview on Feedage: %D9%85%D9%88%D9%82%D8%B9-%D8%A7%D9%87%D9%84-%D8%A7%D9%84%D8%B4%D8%A7%D9%85- Add to My Yahoo! Add to Google! Add to AOL! Add to MSN
Subscribe in NewsGator Online Add to Netvibes Subscribe in Pakeflakes Subscribe in Bloglines Add to Alesti RSS Reader
Add to Feedage.com Groups Add to Windows Live iPing-it Add to Feedage RSS Alerts Add To Fwicki
Meta Tag Analyzer

Meta Tag Analyzer

عدد زوار بلاد الشام
Free counter and web stats
المواضيع الأخيرة
» تحميل برنامج البروكسي
أباتشي خادم HTTP الإصدار 2.0 Emptyالأحد أكتوبر 12, 2014 7:13 am من طرف heba fathy

» سوريا المحتلة العرب
أباتشي خادم HTTP الإصدار 2.0 Emptyالأحد أكتوبر 28, 2012 3:32 am من طرف يعقوب محمد

» الطفولة تتفض.. ( من اطفال العراق الى اطفال سوريا المحتلة ) .. جراحاتكم نعيشها
أباتشي خادم HTTP الإصدار 2.0 Emptyالأربعاء أكتوبر 10, 2012 4:23 am من طرف يعقوب محمد

» من الذي اساءة للنبي الكريم ياقتلة الشعب السوري ؟؟؟
أباتشي خادم HTTP الإصدار 2.0 Emptyالجمعة سبتمبر 21, 2012 4:36 am من طرف يعقوب محمد

» ModemMAX , برنامج ModemMax , تسريع الانترنت , برامج تسريع الاتصال , زيادة سرعة الاتصال , سرعة الاتصال , تحميل برنامج ModemMAX , برنامج ModemMAX الجديد , برنامج ModemMAX كامل مجانا , download ModemMAX
أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء سبتمبر 18, 2012 3:31 pm من طرف rakan-jordan

» S.S.N-تصريحات هامة للعقيد عبدالجبار العكيدي 25-8.mp4
أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء سبتمبر 18, 2012 3:27 pm من طرف rakan-jordan

» الرباعية تسعى لمنظور مشترك حول سوريا المحتلة
أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء سبتمبر 18, 2012 3:26 pm من طرف rakan-jordan

» استشهاد 142 شخص مقتل 40 عنصر من “جيش الاسادي” في سوريا المحتلة
أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء سبتمبر 18, 2012 3:25 pm من طرف rakan-jordan

» نورا الجيزاوي حرة: سمعت بدموع الفرح واليوم تذوقت لذتها on 2012/09/18 09:57 / لا يوجد اي تعليق منذ نعومة أظفاري و أنا بسمع “بدموع الفرح” بس لليوم لحتى تذوقت لذتهم ♥ الله لا يحرم حدا هالشعور يااااا
أباتشي خادم HTTP الإصدار 2.0 Emptyالثلاثاء سبتمبر 18, 2012 3:24 pm من طرف rakan-jordan

سحابة الكلمات الدلالية
والنشر حقوق اللبناني يترتب الرحيل انتهاك مالك إساءة الجزء الطبع بدون الريف يحدث عليه وخيمة الاول غليص