Apache HTTP Server Tutorial: .htaccess files
.htaccess files provide a way to make configuration
changes on a per-directory basis, without modifying the main server
configuration files directly.
.htaccess files
| Related Modules | Related Directives |
|---|---|
What they are/How to use them
.htaccess files (or "distributed configuration files")
provide a way to make configuration changes on a per-directory basis. A
file, containing one or more configuration directives, is placed in a
particular document directory, and the directives apply to that
directory, and all subdirectories thereof.
Note:
If you want to call your .htaccess file something
else, you can change the name of the file using the AccessFileName directive. For example,
if you would rather call the file .config then you
can put the following in your server configuration file:
AccessFileName ".config"
Directives in .htaccess files use the same syntax as
in the main configuration
files. What you are permitted to put in these files is determined by the
AllowOverride and
AllowOverrideList directives.
AllowOverride specifies, in
categories, what directives will be honored if they are found in a
.htaccess file, while AllowOverrideList names individual
directives to permit (see below). If a directive
is permitted, the documentation for that directive will contain an Override section,
specifying what value must be in AllowOverride for that
directive to be permitted.
AllowOverride is None.
This means .htaccess files are completely ignored
unless you explicitly enable them for a directory.For example, if you look at the documentation for the AddDefaultCharset
directive, you will find that it is permitted in .htaccess
files. (See the Context line in the directive summary.) The Override line reads
FileInfo. Thus, you must have at least
AllowOverride FileInfo for this directive to be
honored in .htaccess files.
When (not) to use .htaccess files
If you have access to the main server configuration file, you
should put all of your configuration there instead of in
.htaccess files. This includes user authentication,
mod_rewrite rules, and anything else you might be
tempted to put in .htaccess. Directives in the main
configuration are loaded once at server start, rather than on every
request, and mod_rewrite in particular works better
in server configuration context.
.htaccess files should be used in a case where the
content providers need to make configuration changes to the server on a
per-directory basis, but do not have root access on the server system.
This is common with managed hosting environments, control-panel-based
hosting (such as cPanel or Plesk), and content management systems where
the application ships a .htaccess file as part of its
distribution. In the event that the server administrator is not willing
to make frequent configuration changes, it might be desirable to permit
individual users to make these changes in .htaccess files
for themselves.
There are two reasons to prefer the main configuration file
over .htaccess: performance and security.
Performance: When AllowOverride
is set to allow the use of .htaccess files, httpd will
look in every directory for .htaccess files. Thus,
permitting .htaccess files causes a performance hit,
whether or not you actually even use them! Also, the
.htaccess file is loaded every time a document is
requested.
Additionally, httpd must look for .htaccess files
in all higher-level directories to assemble the full set of applicable
directives. (See section on how
directives are applied.) Thus, if a file is requested out of a
directory /www/htdocs/example, httpd must look for the
following files:
/.htaccess /www/.htaccess /www/htdocs/.htaccess /www/htdocs/example/.htaccess
And so, for each file access out of that directory, there are 4
additional file-system accesses, even if none of those files are
present. (This would only be the case if
.htaccess files were enabled for /, which
is not usually the case.)
Security: You are permitting
users to modify server configuration, which may result in changes over
which you have no control. Carefully consider whether you want to give
your users this privilege. Giving users less
privileges than they need will lead to additional technical support
requests. Make sure you clearly tell your users what level of
privileges you have given them. Specifying exactly what you have set
AllowOverride to, and pointing them
to the relevant documentation, prevents confusion
later.
If you need to grant .htaccess access but want to
limit it to specific directives rather than entire categories, use the
AllowOverrideList directive. This
lets you name individual directives that are permitted, providing
finer-grained control than AllowOverride alone:
# Allow only specific directives, not entire categories AllowOverride None AllowOverrideList Redirect RedirectMatch RewriteEngine RewriteRule RewriteCond
With this configuration, any directive not explicitly listed will
cause a server error if encountered in a .htaccess file.
This is a useful middle ground between full override access and no
override access.
Placing a directive in a .htaccess
file in a directory /www/htdocs/example is completely equivalent to placing that same directive in a
<Directory "/www/htdocs/example"> section in your main server
configuration:
.htaccess file in /www/htdocs/example:
Contents of .htaccess file in
/www/htdocs/example
AddType text/example ".exm"
Section from your httpd.conf
file
<Directory "/www/htdocs/example"> AddType text/example ".exm" </Directory>
The use of .htaccess files can be disabled completely
by setting the AllowOverride
directive to none:
AllowOverride None
How directives are applied
The configuration directives found in a .htaccess file
are applied to the directory in which the .htaccess file
is found, and to all subdirectories thereof. Remember that there may have been .htaccess files
in directories higher up. Directives are applied in the order that they
are found. Therefore, a .htaccess file in a particular
directory may override directives found in .htaccess files
found higher up in the directory tree. And those, in turn, may have
overridden directives found yet higher up, or in the main server
configuration file itself.
Example:
In the directory /www/htdocs/example1 we have a
.htaccess file containing the following:
Options +ExecCGI
AllowOverride Options" in effect
to permit the use of the "Options" directive in
.htaccess files.In the directory /www/htdocs/example1/example2 we have
a .htaccess file containing:
Options Includes
Because of this second .htaccess file, in the directory
/www/htdocs/example1/example2, CGI execution is not
permitted, as only Options Includes is in effect, which
completely overrides any earlier setting that may have been in
place.
Merging of .htaccess with the main configuration files
As discussed in the documentation on Configuration Sections,
.htaccess files can override the <Directory> sections for
the corresponding directory, but will be overridden by other types
of configuration sections from the main configuration files. This
fact can be used to enforce certain configurations, even in the
presence of a liberal AllowOverride setting. For example, to
prevent script execution while allowing anything else to be set in
.htaccess you can use:
<Directory "/www/htdocs"> AllowOverride All </Directory> <Location "/"> Options +IncludesNoExec -ExecCGI </Location>
DocumentRoot is /www/htdocs.Authentication example
As with any .htaccess use, placing these directives in
a <Directory> block is
preferred when you have access to the main configuration (see
above). The following example shows the
.htaccess approach:
.htaccess file contents:
AuthType Basic AuthName "Password Required" AuthUserFile "/www/passwords/password.file" AuthGroupFile "/www/passwords/group.file" Require group admins
AllowOverride AuthConfig must be in effect
for these directives to have any effect.Please see the authentication tutorial for a more complete discussion of authentication and authorization.
Server Side Includes example
Another use of .htaccess files is to enable Server Side
Includes for a particular directory. This may be done with the following
configuration directives, placed in a .htaccess file in
the desired directory:
Options +Includes AddType text/html "shtml" AddHandler server-parsed shtml
AllowOverride Options and AllowOverride
FileInfo must both be in effect for these directives to have any
effect.Please see the SSI tutorial for a more complete discussion of server-side includes.
Rewrite Rules in .htaccess files
When using RewriteRule in
.htaccess files, be aware that the per-directory context
changes things a bit. In particular, rules are taken to be relative to
the current directory, rather than being the original requested URI.
Consider the following examples:
# In httpd.conf RewriteRule "^/images/(.+)\.jpg" "/images/$1.png" # In .htaccess in root dir RewriteRule "^images/(.+)\.jpg" "images/$1.png" # In .htaccess in images/ RewriteRule "^(.+)\.jpg" "$1.png"
In a .htaccess in your document directory, the leading
slash is removed from the value supplied to RewriteRule, and in the
images subdirectory, /images/ is removed from
it. Thus, your regular expression needs to omit that portion as
well.
In .htaccess context, regular expressions are
recompiled on every request, whereas in the main server configuration they
are compiled once and cached.
Consult the mod_rewrite documentation for
further details on using mod_rewrite.
CGI example
mod_proxy_fcgi with a
FastCGI application server, or a framework-specific handler. The
information below remains useful for environments that still rely on
traditional CGI.You may wish to use a .htaccess file to permit the
execution of CGI programs in a particular directory. This may be
implemented with the following configuration:
Options +ExecCGI AddHandler cgi-script "cgi" "py"
Alternately, if you wish to have all files in the given directory be considered to be CGI programs, this may be done with the following configuration:
Options +ExecCGI SetHandler cgi-script
AllowOverride Options and AllowOverride
FileInfo must both be in effect for these directives to have any
effect.Please see the CGI tutorial for a more complete discussion of CGI programming and configuration.
Troubleshooting
When you put configuration directives in a .htaccess
file, and you don't get the desired effect, there are a number of
things that may be going wrong.
Most commonly, the problem is that AllowOverride is not
set such that your configuration directives are being honored. Make
sure that you don't have a AllowOverride None in effect
for the file scope in question. A good test for this is to put a
nonsense word in your .htaccess file and reload the
page:
TestMe
If a server error (HTTP 500) is
not generated, then you almost certainly have AllowOverride
None in effect.
If, on the other hand, you are getting server errors when trying to
access documents, check your httpd error log. It will likely tell you
that the directive used in your .htaccess file is not
permitted.
[Thu Jun 18 09:12:31.528374 2026] [core:alert] [pid 12345] [client 192.168.1.50:54321] /var/www/html/.htaccess: DirectoryIndex not allowed here
This will indicate either that you've used a directive that is
never permitted in .htaccess files, or that you don't have AllowOverride set to
a level sufficient for the directive you've used. Consult the
documentation for that particular directive to determine which is
the case.
Alternately, it may tell you that you had a syntax error in your usage of the directive itself.
[Thu Jun 18 09:14:02.946218 2026] [core:alert] [pid 12345] [client 192.168.1.50:54321] /var/www/html/.htaccess: RewriteCond: bad flag delimiters
In this case, the error message should be specific to the particular syntax error that you have committed.
دليل خادم Apache HTTP Server التعليمي: ملفات .htaccess
.htaccessتوفّر الملفات طريقة لإجراء تغييرات في التهيئة
على أساس كل دليل، من دون تعديل ملفات تهيئة الخادم الرئيسية
مباشرةً.
ملفات .htaccess
| الوحدات ذات الصلة | التوجيهات ذات الصلة |
|---|---|
ما هي/كيفية استخدامها
.htaccessتوفّر الملفات (أو "ملفات التهيئة الموزّعة")
طريقة لإجراء تغييرات في التهيئة على أساس كل دليل. يُوضَع
ملف، يحتوي على توجيه تهيئة واحد أو أكثر، في دليل مستندات
معيّن، وتنطبق التوجيهات على ذلك
الدليل، وعلى جميع الأدلة الفرعية التابعة له.
ملاحظة:
إذا كنت تريد تسمية ملف .htaccess باسم آخر، يمكنك تغيير اسم الملف باستخدام التوجيه AccessFileName. على سبيل المثال،
إذا كنت تفضّل تسمية الملف .config فيمكنك
وضع ما يلي في ملف تهيئة الخادم الخاص بك:
AccessFileName ".config"
التوجيهات في .htaccess تستخدم الملفات نفس الصياغة كما
في ملفات التكوين
الرئيسية. ما يُسمح لك بوضعه في هذه الملفات يُحدَّد بواسطة
AllowOverride و
AllowOverrideList التوجيهات.
AllowOverrideيحدّد، ضمن
فئات، ما التوجيهات التي سيجري احترامها إذا وُجدت في
.htaccess ملف، بينما AllowOverrideList يسمّي توجيهات فردية
للسماح بها (انظر أدناه). إذا كان التوجيه
مسموحًا به، فستتضمن وثائق ذلك التوجيه قسم Override،
يحدد القيمة التي يجب أن تكون في AllowOverride لكي يُسمح بذلك
التوجيه.
AllowOverride هي None.
وهذا يعني أن ملفات .htaccess يتم تجاهلها بالكامل
ما لم تقم بتمكينها صراحةً لدليلٍ ما.على سبيل المثال، إذا نظرت إلى توثيق التوجيه AddDefaultCharset
فستجد أنه مسموح به في ملفات .htaccess
. (انظر سطر السياق في ملخص التوجيه.) يقرأ سطر Override على النحو التالي
FileInfo. لذلك، يجب أن يكون لديك على الأقل
AllowOverride FileInfo لكي يتم احترام هذا التوجيه في ملفات .htaccess.
متى (لا) تستخدم ملفات .htaccess
إذا كان لديك وصول إلى ملف التهيئة الرئيسي للخادم، فينبغي أن تضع كل تهيئتك هناك بدلًا من وضعها في .htaccessالملفات. ويشمل ذلك مصادقة المستخدم، وmod_rewriteالقواعد، وأي شيء آخر قد تميل إلى وضعه في .htaccess. تُحمَّل التوجيهات في التهيئة الرئيسية مرة واحدة عند بدء تشغيل الخادم، بدلًا من تحميلها عند كل mod_rewriteطلب، و يعمل خصوصًا بشكل أفضل في سياق تهيئة الخادم.
.htaccessينبغي استخدام الملفات في حالة يحتاج فيها
مزوّدو المحتوى إلى إجراء تغييرات في التهيئة على الخادم
على أساس كل دليل، ولكن لا يملكون صلاحية الجذر على نظام الخادم.
وهذا شائع في بيئات الاستضافة المُدارة، والاستضافة القائمة على لوحات التحكم
(مثل cPanel أو Plesk)، وأنظمة إدارة المحتوى حيث
يرفق التطبيق ملف .htaccess كجزء من
توزيعه. في حال لم يكن مسؤول الخادم راغبًا
في إجراء تغييرات متكررة على التهيئة، فقد يكون من المرغوب السماح
للمستخدمين الفرديين بإجراء هذه التغييرات في .htaccess ملفات
لأنفسهم.
هناك سببان لتفضيل ملف التهيئة الرئيسي
على .htaccess: الأداء والأمان.
الأداء: عندما AllowOverride
يُضبط للسماح باستخدام ملفات .htaccess، سيبحث httpd
في كل دليل عن ملفات .htaccess. وبالتالي،
فإن السماح بملفات .htaccess يسبب انخفاضًا في الأداء،
سواء كنت تستخدمها فعليًا أم لا! كذلك، يتم تحميل
ملف .htaccess في كل مرة يُطلب فيها مستند.
بالإضافة إلى ذلك، يجب على httpd البحث عن .htaccessالملفات
في جميع الأدلة ذات المستوى الأعلى لتجميع المجموعة الكاملة من
التوجيهات المنطبقة. (انظر القسم حول كيفية
تطبيق التوجيهات.) لذلك، إذا طُلب ملف من
دليل ما /www/htdocs/example، فيجب على httpd البحث عن
الملفات التالية:
/.htaccess /www/.htaccess /www/htdocs/.htaccess /www/htdocs/example/.htaccess
وبذلك، فمقابل كل وصول إلى ملف من ذلك الدليل، توجد 4
عمليات وصول إضافية إلى نظام الملفات، حتى إذا لم يكن أيٌّ من تلك الملفات
موجودًا. (لن يكون هذا هو الحال إلا إذا
.htaccess تم تمكين الملفات لـ /، وهو
ليس الحال عادةً.)
الأمان: إنك تسمح
للمستخدمين بتعديل تكوين الخادم، مما قد يؤدي إلى تغييرات
لا تملك أي سيطرة عليها. فكّر بعناية فيما إذا كنت تريد
منح مستخدميك هذا الامتياز. إن منح المستخدمين امتيازات أقل
مما يحتاجون سيؤدي إلى طلبات دعم فني إضافية. تأكد من أن تخبر مستخدميك بوضوح بمستوى
الامتيازات الذي منحته لهم. إن تحديد ما عيّنته بالضبط
AllowOverride إلى، وتوجيههم
إلى الوثائق ذات الصلة، يمنع الالتباس
لاحقًا.
إذا كنت بحاجة إلى منح وصول .htaccess ولكنك تريد
قصره على توجيهات محددة بدلًا من فئات كاملة، فاستخدم التوجيه
AllowOverrideList. يتيح لك ذلك
تسمية التوجيهات الفردية المسموح بها، مما يوفر
تحكمًا أدق من AllowOverride وحده:
# Allow only specific directives, not entire categories AllowOverride None AllowOverrideList Redirect RedirectMatch RewriteEngine RewriteRule RewriteCond
مع هذا التكوين، فإن أي توجيه غير مُدرَج صراحةً سيؤدي
إلى خطأ في الخادم إذا صودف في ملف .htaccess.
وهذا حل وسط مفيد بين الوصول الكامل للتجاوز وعدم
وجود وصول للتجاوز.
وضع توجيه في .htaccess
ملف في دليل /www/htdocs/example يعادل تمامًا وضع ذلك التوجيه نفسه في
<Directory "/www/htdocs/example"> قسم في تهيئة الخادم الرئيسية
الخاصة بك:
.htaccess ملف في /www/htdocs/example:
محتويات ملف .htaccess في
/www/htdocs/example
AddType text/example ".exm"
قسم من الخاص بك httpd.conf
ملف
<Directory "/www/htdocs/example"> AddType text/example ".exm" </Directory>
استخدام .htaccessيمكن تعطيل الملفات تمامًا
من خلال ضبط AllowOverride
التوجيه إلى none:
AllowOverride None
كيفية تطبيق التوجيهات
تُطبَّق توجيهات التهيئة الموجودة في ملف .htaccess
على الدليل الذي يوجد فيه ملف .htaccess
وعلى جميع أدلته الفرعية. تذكّر أنه ربما كانت هناك ملفات .htaccess
في أدلة أعلى. تُطبَّق التوجيهات بالترتيب الذي
تُعثَر فيه. لذلك، قد يتجاوز ملف .htaccess في دليل معيّن
التوجيهات الموجودة في ملفات .htaccess
الموجودة في مستوى أعلى في شجرة الأدلة. وهذه بدورها ربما تكون قد
تجاوزت توجيهات وُجدت في مستوى أعلى أيضًا، أو في ملف تهيئة الخادم
الرئيسي نفسه.
مثال:
في الدليل /www/htdocs/example1 لدينا ملف
.htaccess يحتوي على ما يلي:
Options +ExecCGI
AllowOverride Options" ساري المفعول
للسماح باستخدام "Options" التوجيه في
.htaccess الملفات.في الدليل /www/htdocs/example1/example2 لدينا
ملف .htaccess يحتوي على:
Options Includes
بسبب هذه الثانية .htaccess الملف، في الدليل
/www/htdocs/example1/example2، لا يُسمح بتنفيذ CGI، إذ إنّه فقط Options Includesسارٍ، وهو
يتجاوز تمامًا أي إعداد سابق ربما كان
موجودًا.
دمج ملفات .htaccess مع ملفات التهيئة الرئيسية
كما نوقش في الوثائق حول أقسام التكوين،
.htaccess يمكن أن تتجاوز الملفات أقسام <Directory> للدليل
المقابل، ولكن ستتجاوزها أنواع أخرى
من أقسام التكوين من ملفات التكوين الرئيسية. يمكن استخدام
هذه الحقيقة لفرض تكوينات معينة، حتى في ظل وجود إعداد AllowOverride متساهل. على سبيل المثال، من أجل
منع تنفيذ السكربتات مع السماح بتعيين أي شيء آخر في
.htaccess يمكنك استخدام:
<Directory "/www/htdocs"> AllowOverride All </Directory> <Location "/"> Options +IncludesNoExec -ExecCGI </Location>
DocumentRoot لديك هو /www/htdocs.مثال المصادقة
كما هو الحال مع أي استخدام لـ .htaccess، فإن وضع هذه التوجيهات في
<Directory>تُفضَّل الكتلة عندما يكون لديك وصول إلى التهيئة الرئيسية (انظر
أعلاه). يوضّح المثال التالي
.htaccessالنهج:
.htaccessمحتويات الملف:
AuthType Basic AuthName "Password Required" AuthUserFile "/www/passwords/password.file" AuthGroupFile "/www/passwords/group.file" Require group admins
AllowOverride AuthConfigيجب أن يكون ساري المفعول
لكي يكون لهذه التوجيهات أي تأثير.يرجى الاطلاع على الدليل التعليمي للمصادقة للحصول على مناقشة أكثر اكتمالًا حول المصادقة والتفويض.
مثال على Server Side Includes
استخدام آخر لملفات .htaccess هو تمكين Server Side
Includes لدليل معيّن. ويمكن القيام بذلك باستخدام توجيهات
التكوين التالية، الموضوعة في .htaccess ملف في
الدليل المطلوب:
Options +Includes AddType text/html "shtml" AddHandler server-parsed shtml
AllowOverride Options وAllowOverride
FileInfo يجب أن يكونا كلاهما مفعّلين لكي يكون لهذه التوجيهات أي
تأثير.يرجى الاطلاع على دليل SSI لمناقشة أكثر اكتمالًا للتضمينات من جانب الخادم.
قواعد إعادة الكتابة في ملفات .htaccess
عند استخدام RewriteRule في
.htaccess الملفات، انتبه إلى أن سياق كل دليل
يغيّر الأمور قليلًا. وعلى وجه الخصوص، تُعدّ القواعد نسبية إلى
الدليل الحالي، بدلًا من أن تكون نسبةً إلى معرّف URI الأصلي المطلوب.
انظر في الأمثلة التالية:
# In httpd.conf RewriteRule "^/images/(.+)\.jpg" "/images/$1.png" # In .htaccess in root dir RewriteRule "^images/(.+)\.jpg" "images/$1.png" # In .htaccess in images/ RewriteRule "^(.+)\.jpg" "$1.png"
في .htaccess في دليل مستنداتك، تُزال الشرطة المائلة
البادئة من القيمة المقدمة إلى RewriteRule، وفي
images الدليل الفرعي، /images/ تتم إزالته منه.
لذلك، يجب أن يُسقط تعبيرك النمطي ذلك الجزء أيضًا.
في .htaccessالسياق، تُعاد ترجمة التعبيرات النمطية
في كل طلب، بينما في التهيئة الرئيسية للخادم
تُترجم مرة واحدة وتُخزَّن مؤقتًا.
راجِع توثيق mod_rewrite لمزيد من التفاصيل حول استخدام mod_rewrite.
مثال CGI
mod_proxy_fcgi مع خادم تطبيقات FastCGI، أو معالج خاص بإطار العمل. تظل المعلومات أدناه مفيدة للبيئات التي لا تزال تعتمد على CGI التقليدي.قد ترغب في استخدام ملف .htaccess للسماح بتنفيذ برامج CGI في دليل معيّن. يمكن تنفيذ ذلك باستخدام التهيئة التالية:
Options +ExecCGI AddHandler cgi-script "cgi" "py"
وبدلًا من ذلك، إذا كنت ترغب في اعتبار جميع الملفات الموجودة في الدليل المحدد برامج CGI، فيمكن القيام بذلك باستخدام التهيئة التالية:
Options +ExecCGI SetHandler cgi-script
AllowOverride Options وAllowOverride
FileInfo يجب أن يكونا كلاهما مفعّلين لكي يكون لهذه التوجيهات أي تأثير.يرجى الاطلاع على البرنامج التعليمي لـ CGI للحصول على مناقشة أكثر اكتمالًا لبرمجة CGI وتهيئتها.
استكشاف الأخطاء وإصلاحها
عندما تضع توجيهات التهيئة في ملف .htaccess، ولا تحصل على التأثير المطلوب، فهناك عدد من الأمور التي قد تكون خاطئة.
في أغلب الأحيان، تكون المشكلة هي أن AllowOverride لم يتم
ضبطه بحيث يتم الالتزام بتوجيهات التهيئة الخاصة بك. تأكد من عدم وجود AllowOverride None ساري المفعول
لنطاق الملف المعني. اختبار جيد لذلك هو أن تضع
كلمة بلا معنى في ملف .htaccess الخاص بك وتعيد تحميل
الصفحة:
TestMe
إذا لم يتم إنشاء خطأ في الخادم (HTTP 500)،
فمن شبه المؤكد أن لديك AllowOverride
None ساري المفعول.
أما إذا كنت، من ناحية أخرى، تتلقى أخطاء في الخادم عند محاولة
الوصول إلى المستندات، فتحقق من سجل أخطاء httpd لديك. من المرجح أن يخبرك
بأن التوجيه المستخدم في ملف .htaccess الخاص بك غير
مسموح به.
[Thu Jun 18 09:12:31.528374 2026] [core:alert] [pid 12345] [client 192.168.1.50:54321] /var/www/html/.htaccess: DirectoryIndex not allowed here
سيشير هذا إما إلى أنك استخدمت توجيهًا غير مسموح به مطلقًا في ملفات .htaccess، أو إلى أنك لا تملك AllowOverride مضبوطًا على
مستوى كافٍ للتوجيه الذي استخدمته. راجع
الوثائق الخاصة بذلك التوجيه المحدد لتحديد أي الحالتين
تنطبق.
بدلًا من ذلك، قد يخبرك بأن لديك خطأً نحويًا في استخدامك للتوجيه نفسه.
[Thu Jun 18 09:14:02.946218 2026] [core:alert] [pid 12345] [client 192.168.1.50:54321] /var/www/html/.htaccess: RewriteCond: bad flag delimiters
في هذه الحالة، ينبغي أن تكون رسالة الخطأ محددةً للخطأ النحوي المعين الذي ارتكبته.
Frequently asked questions · الأسئلة الشائعة
What is an .htaccess file in Apache HTTP Server?وش هو ملف .htaccess في خادم Apache HTTP Server؟
An .htaccess file is a distributed configuration file placed in a document directory. Its directives apply to that directory and its subdirectories, allowing per-directory configuration without directly editing the main server configuration files.
ملف .htaccess هو ملف إعدادات موزّع ينحط داخل مجلد من مجلدات المستندات. التوجيهات اللي فيه تطبّق على هذا المجلد وكل المجلدات الفرعية تحته، ويمكّن من إعدادات لكل مجلد بدون تعديل ملفات إعدادات الخادم الرئيسية مباشرة.
When should an enterprise use .htaccess instead of the main Apache configuration?متى تستخدم المنشأة .htaccess بدل إعدادات Apache الرئيسية؟
Use .htaccess only when content providers need per-directory configuration changes but do not have access to the main server configuration, such as in managed hosting, control-panel hosting, or applications that ship an .htaccess file. If you can edit the main server configuration, Apache recommends putting the configuration there instead.
استخدم .htaccess فقط إذا كان مزوّدو المحتوى يحتاجون تغييرات إعدادات على مستوى المجلد وما عندهم وصول لملف إعدادات الخادم الرئيسي، مثل الاستضافة المُدارة أو الاستضافة عبر لوحات التحكم أو التطبيقات اللي تجي معها ملفات .htaccess. إذا تقدر تعدّل إعدادات الخادم الرئيسية، فتوصية Apache إنك تحط الإعدادات هناك بدلاً من .htaccess.
What must be enabled before Apache honors directives in .htaccess files?وش المتطلبات قبل ما Apache يعتمد التوجيهات داخل ملفات .htaccess؟
The relevant directory must explicitly allow .htaccess processing. By default, AllowOverride is None, so .htaccess files are ignored. The directive used inside .htaccess must also be permitted by AllowOverride or by AllowOverrideList.
لازم المجلد المعني يسمح صراحةً بمعالجة ملفات .htaccess. القيمة الافتراضية لـ AllowOverride هي None، لذلك يتم تجاهل ملفات .htaccess. كذلك لازم يكون التوجيه المستخدم داخل .htaccess مسموح به عبر AllowOverride أو AllowOverrideList.
What are the main risks of enabling .htaccess files?وش أبرز مخاطر تفعيل ملفات .htaccess؟
The two main concerns are performance and security. Apache may check multiple directories for .htaccess files on each request, which adds file-system access overhead. Security-wise, enabling .htaccess allows users to modify server behavior, so administrators should grant only the needed level of override access and document it clearly.
أهم نقطتين هي الأداء والأمان. قد يفحص Apache عدة مجلدات بحثاً عن ملفات .htaccess مع كل طلب، وهذا يزيد عمليات الوصول لنظام الملفات. ومن ناحية الأمان، تفعيل .htaccess يسمح للمستخدمين بتعديل سلوك الخادم، لذلك لازم المسؤول يعطي أقل صلاحيات override مطلوبة ويوضحها للمستخدمين بشكل واضح.
How can an administrator limit which directives are allowed in .htaccess?كيف يقدر المسؤول يحدّد التوجيهات المسموحة داخل .htaccess؟
Use AllowOverrideList to permit only named directives instead of broad AllowOverride categories. For example, an administrator can set AllowOverride None and then list specific permitted directives with AllowOverrideList. Any directive not explicitly listed will cause a server error if it appears in an .htaccess file.
استخدم AllowOverrideList للسماح بتوجيهات محددة بالاسم بدلاً من فئات AllowOverride الواسعة. مثلاً يقدر المسؤول يضبط AllowOverride None ثم يذكر التوجيهات المسموحة تحديداً عبر AllowOverrideList. أي توجيه غير مذكور صراحةً راح يسبب خطأ في الخادم إذا ظهر داخل ملف .htaccess.
How can a team validate that an .htaccess directive is allowed?كيف يتحقق الفريق أن توجيه داخل .htaccess مسموح؟
Check the documentation for the directive and look at its Override section. That section states which AllowOverride value is required for the directive to be honored in .htaccess. If the directive is controlled through AllowOverrideList, confirm it is explicitly listed.
راجع توثيق التوجيه وانظر لقسم Override. هذا القسم يوضح قيمة AllowOverride المطلوبة عشان يتم اعتماد التوجيه داخل .htaccess. وإذا كان التحكم عبر AllowOverrideList، تأكد أن التوجيه مذكور صراحةً في القائمة.
Why might an .htaccess change not take effect?ليش ممكن تغيير .htaccess ما يطبّق؟
Common causes are that AllowOverride is set to None, the required AllowOverride category is not enabled, the directive is not included in AllowOverrideList, or another .htaccess file lower in the directory tree overrides an earlier setting. Also remember that higher-level .htaccess files may apply before the file in the requested directory.
الأسباب الشائعة تشمل أن AllowOverride مضبوط على None، أو فئة AllowOverride المطلوبة غير مفعّلة، أو التوجيه غير موجود في AllowOverrideList، أو فيه ملف .htaccess أدنى في شجرة المجلدات غيّر إعداد سابق. تذكر أيضاً أن ملفات .htaccess في المجلدات الأعلى قد تطبّق قبل الملف الموجود في مجلد الطلب.
When should an issue be escalated to the server administrator?متى يتم تصعيد المشكلة لمسؤول الخادم؟
Escalate when the required directive is not permitted by AllowOverride or AllowOverrideList, when main server configuration changes are needed, or when the organization needs to enforce settings that .htaccess users should not override. Only administrators with access to the main configuration can change those controls.
صعّد للمسؤول إذا كان التوجيه المطلوب غير مسموح عبر AllowOverride أو AllowOverrideList، أو إذا كانت هناك حاجة لتعديل إعدادات الخادم الرئيسية، أو إذا كانت الجهة تحتاج فرض إعدادات ما ينبغي لمستخدمي .htaccess تجاوزها. فقط المسؤولون اللي عندهم وصول للإعدادات الرئيسية يقدرون يغيّرون هذه الضوابط.
Is .htaccess relevant for regional managed-hosting environments?هل .htaccess مهم في بيئات الاستضافة المُدارة محلياً وإقليمياً؟
Yes. The article specifically notes that .htaccess is common in managed hosting, control-panel hosting such as cPanel or Plesk, and content management systems that include an .htaccess file. This applies operationally wherever those hosting models are used, including Saudi and regional enterprise hosting environments.
نعم. المقال يوضح أن .htaccess شائع في الاستضافة المُدارة، والاستضافة عبر لوحات التحكم مثل cPanel أو Plesk، وأنظمة إدارة المحتوى اللي تتضمن ملف .htaccess. وهذا ينطبق تشغيلياً في أي مكان تُستخدم فيه هذه النماذج، بما فيها بيئات استضافة الشركات في السعودية والمنطقة.
What is the recommended next action before enabling .htaccess in production?وش الخطوة الموصى بها قبل تفعيل .htaccess في بيئة الإنتاج؟
First decide whether the configuration can be placed in the main Apache configuration instead. If .htaccess is necessary, enable it only for the required directory, grant the minimum needed permissions with AllowOverride or AllowOverrideList, and clearly document the allowed privileges for users.
أولاً قرر هل يمكن وضع الإعدادات في ملف إعدادات Apache الرئيسي بدلاً من .htaccess. إذا كان .htaccess ضروري، فعّله فقط للمجلد المطلوب، وامنح أقل صلاحيات لازمة باستخدام AllowOverride أو AllowOverrideList، ووثّق بوضوح الصلاحيات المسموحة للمستخدمين.
Related reading
Knowledge base
Log FilesKnowledge base
Getting StartedKnowledge base
Name-based Virtual Host SupportArticle
Website Migration to a KSA Data Center: The Zero-Downtime Technical Playbook (GCC & MENA)Migrate to a KSA data center with zero downtime: staging checks, DNS TTL plan, DB sync, SSL, email, SEO safety, rollback, monitoring. Saudi, GCC MENA.
Service
Amaan™ SSL The Shield of Digital Trust: أمان™ SSL درع الثقة الرقمية للمملكةSSL certificates in Saudi Arabia with trusted HTTPS encryption, browser security, and business credibility for websites, portals, and eCommerce KSA.