fbpx Htaccess - Meysmahdavi

Tag Archive :Htaccess

What is HSTS ?

HTTP Strict Transport Security (HSTS) is a web security policy mechanism that helps to protect websites against man-in-the-middle attacks such as protocol downgrade attacks and cookie hijacking. It allows web servers to declare that web browsers (or other complying user agents) should automatically interact with it using only HTTPS connections, which provide Transport Layer Security (TLS/SSL), unlike the insecure HTTP used alone. HSTS is an IETF standards track protocol and is specified in RFC 6797.

The HSTS Policy is communicated by the server to the user agent via an HTTPS response header field named “Strict-Transport-Security“. HSTS Policy specifies a period of time during which the user agent should only access the server in a secure fashion. Websites using HSTS often do not accept clear text HTTP, either by rejecting connections over HTTP or systematically redirecting users to HTTPS (though this is not required by the specification). The consequence of this is that a user-agent not capable of doing TLS will not be able to connect to the site.

The protection only applies after a user has visited the site at least once, and the way this protection works is that a user entering or selecting a URL to the site that specifies HTTP, will automatically upgrade to HTTPS, without making an HTTP request, which prevents the HTTP man-in-the-middle attack from occurring.

Submission Requirements

If a site sends the preload directive in an HSTS header, it is considered to be requesting inclusion in the preload list and may be submitted via the form on this site.

In order to be accepted to the HSTS preload list through this form, your site must satisfy the following set of requirements:

  1. Serve a valid certificate.
  2. Redirect from HTTP to HTTPS on the same host, if you are listening on port 80.
  3. Serve all subdomains over HTTPS.
    • In particular, you must support HTTPS for the www subdomain if a DNS record for that subdomain exists.
  4. Serve an HSTS header on the base domain for HTTPS requests:
    • The max-age must be at least 31536000 seconds (1 year).
    • The includeSubDomains directive must be specified.
    • The preload directive must be specified.
    • If you are serving an additional redirect from your HTTPS site, that redirect must still have the HSTS header (rather than the page it redirects to).

of a valid HSTS header: (You can add this code is .htaccess)

Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

You can check the status of your request by entering the domain name again in the form above, or consult the current Chrome preload list by visiting chrome://net-internals/#hsts in your browser. Note that new entries are hardcoded into the Chrome source code and can take several months before they reach the stable version.

Continued Requirements

You must make sure your site continues to satisfy the submission requirements at all times. Note that removing the preload directive from your header will make your site immediately eligible for the removal form, and that sites may be removed automatically in the future for failing to keep up the requirements.

Deployment Recommendations

If your site is committed to HTTPS and you want to preload HSTS, we suggest the following steps:

  1. Examine all subdomains (and nested subdomains) of your site and make sure that they work properly over HTTPS.
  2. Add the Strict-Transport-Security header to all HTTPS responses and ramp up the max-age in stages, using the following header values:
    • 5 minutes:
      max-age=300; includeSubDomains
    • 1 week:
      max-age=604800; includeSubDomains
    • 1 month:
      max-age=2592000; includeSubDomains

    During each stage, check for broken pages and monitor your site’s metrics (e.g. traffic, revenue). Fix any problems that come up and then wait the full max-age of the stage before you move on. For example, wait a month in the last stage.

  3. Once you’re confident that there will be no more issues, increase the max-age to 2 years and submit your site to the preload list:
    • 2 years, requesting to be preloaded:
      max-age=63072000; includeSubDomains; preload

If you have a group of employees or users who can beta test the deployment, consider trying the first few ramp-up stages on those users. Then make sure to go through all stages for all users, starting over from the beginning.

Consult the Mozilla Web Security guidelines and the Google Web Fundamentals pages on security for more concrete advice about HTTPS deployment.

Preloading Should Be Opt-In

If you maintain a project that provides HTTPS configuration advice or provides an option to enable HSTS, do not include the preload directive by default. We get regular emails from site operators who tried out HSTS this way, only to find themselves on the preload list by the time they find they need to remove HSTS to access certain subdomains. Removal tends to be slow and painful for those sites.

It’s great to support HSTS preloading as a best practice, and for projects to provide a simple option to enable it. However, site operators who enable HSTS should know about the long-term consequences of preloading before they turn it on for a given domain.

Removal

Be aware that inclusion in the preload list cannot easily be undone. Domains can be removed, but it takes months for a change to reach users with a Chrome update and we cannot make guarantees about other browsers. Don’t request inclusion unless you’re sure that you can support HTTPS for your entire site and all its subdomains in the long term.

Htaccess چیست ؟

فایل htaccess ، یک فایل پیکربندی وب سرور آپاچی است که میتواند دسترسی به سایت یا نحوه عملکرد آن را کنترل کند. این فایل می تواند تنظیمات پیش فرض سرور آپاچی را تغییر می دهد. یک فایل htaccess به راحتی می تواند با ویرایشگر text / HTML ایجاد شود و سپس از طریق FTP آپلود شود. اطمینان حاصل کنید که این فایل  را در دایرکتوری که میخواهید آن را کنترل کنید ایجاد یا آپلود شده باشد. اگر از یک فایل htaccess برای کنترل کل سایت استفاده می کنید، باید فایل htaccess را در پوشه عمومی خود آپلود کنید.

فایل htaccess یک فایل مخفی است. علامت “.” در ابتدای فایل htaccess آن را به یک فایل مخفی برای اهداف امنیتی تبدیل می کند. بنابراین اگر آن را از طریق FTP آپلود کنید، در لیست فهرست برنامه FTP شما نمایش داده نخواهد شد؛ مگر اینکه FTP شما ویژگی ای داشته باشد که به شما این امکان را می دهد که فایل های پنهان را مشاهده کنید (اکثر برنامه های FTP دارای این گزینه هستند). اگر شما نیاز به ایجاد تغییرات در فایل htaccess دارید، فقط یک نسخه جدید را آپلود کنید و فایل موجود را بازنویسی کنید.

ساخت فایل htaccess

شما می توانید یک فایل htaccess در رایانه یا در سرور ایجاد کنید. این کار بسیار ساده است. برای ایجاد فایل htaccess در ویندوز کافی است با استفاده از Notepad فایل را با نام htaccess ذخیره کنید. دقت کنید بعد از ذخیره فایل، با استفاده از سرویس گیرنده FTP دلخواه می توانید فایل را در هاست یا سرور خود ذخیره کنید. فایل htaccess باید در پوشه ای قرار گیرد که سایت شما در آن قرار دارد، معمولا این پوشه public_html است.

ایجاد فایل htaccess در هاست یا سرور

به اکانت cPanel خود وارد شوید. روی آیکون File Manager که در قسمت Files قرار دارد کلیک کنید.

از پنجره باز شده در فایل منو گزینه “Choose Hidden Files (dotfiles)” را انتخاب کنید. اگر این پنجره را نمی بینید، باید روی لینک “reset all interface settings” در پایین صفحه cPanel کلیک کنید. از پنجره File Manager پوشه ای که می خواهید باز کنید را انتخاب کنید، اغلب این پوشه در مسیر “Web Root (public_html / www)” است. توجه کنید اگر شما در حال مدیریت فایل هستید، می توانید (& showhidden = 1) را در انتهای  URL اضافه کنید. برای ایجاد یک فایل جدید و روی آیکون New File کلیک کنید و نام آن را .htaccess قرار دهید.

What is htaccess ?

An .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, used for configuration of website-access issues, such as URL redirection, URL shortening, access control (for different web pages and files), and more. The ‘dot’ (period or full stop) before the file name makes it a hidden file in Unix-based environments.

A site could have more than one .htaccess file, and the files are placed inside the web tree (i.e. inside directories and their sub-directories), and hence their other name distributed configuration files.

.htaccess files act as a subset of the server’s global configuration file (like httpd.conf) for the directory that they are in, or all sub-directories.

The original purpose of .htaccess—reflected in its name—was to allow per-directory access control by, for example, requiring a password to access World Wide Web content. More commonly, however, the .htaccess files define or override many other configuration settings such as content type, character set, Common Gateway Interface handlers, etc.

Format and language:

.htaccess files are written in the Apache Directives variant of the Perl Compatible Regular Expressions (PCRE) language. Learning basic PCRE itself can help in mastering work with these files.

For historical reasons, the format of .htaccess files is a limited subset of the Apache HTTP server’s global configuration file httpd.conf even when used with web servers such as Oracle iPlanet Web Server and Zeus Web Server which have very different native global configuration files.

حذف دو یا چند اسلش / از آدرس سایت یا لینکه ها

اگر درخواست URI یا آدرس دارید که شامل چند اسلش پی در پی است ناراحت نباشید. این موضوعی است که در طول سالها بسیاری از مدیران را آزار داده است. خوشبختانه حل این مسئله با استفاده از یک کد با استفاده از .htaccess ساده است. تمام کاری که شما باید انجام دهید این است که کد زیر را کپی کرده و در هر جایی که فایل .htaccess در ریشه سایت خود قرار دارد بگذارید :

 

<IfModule mod_rewrite.c>
RewriteBase /
# Rule 1: remove multiple leading slashes (directly after the TLD)
RewriteCond %{THE_REQUEST} \s/{2,}
RewriteRule (.*) $1 [R=301,L]
# Rule 2: remove multiple slashes in the requested path
RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
RewriteRule (.*) %1/%2 [R=301,L]
</IfModule>

 

به عنوان مثال ، این دستورالعمل به صورت زیر هدایت می شود :

  • https://www.meysmahdavi.com// redirects to https://www.meysmahdavi.com/
  • https://www.meysmahdavi.com//blog-post/ redirects to https://www.meysmahdavi.com/blog-post/
  • https://www.meysmahdavi.com//path/directory/ redirects to https://www.meysmahdavi.com/path/directory/

بنابراین اساساً اسلش های مضاعف را از هر URL حذف می کند.

در مثال بالا همه چیز درست است و اسلش کاملا حذف میشود. تنها ویرایشی که لازم است شما انجام دهید نام دامنه است ، به سادگی Meysmahdavi را با دامنه خود جایگزین کنید و کار شما تمام شده است. فراموش نکنید که همیشه همه چیز را اول کاملاً آزمایش کنید.

ما از کد بالا استفاده میکنیم شما میتوانید تست کنید.

https://www.meysmahdavi.com////blog

Removing double or more slashes from URL by .htaccess

If you’re getting URI requests that include the dreaded “multi forward slash”, you’re not alone. It’s an issue that has plagued many an administrator over the years. Fortunately, the situation is simple to resolve using a tasty slice of .htaccess. All you need to do is copy the following code and place it anywhere in your site’s root .htaccess file:

 

<IfModule mod_rewrite.c>
RewriteBase /
# Rule 1: remove multiple leading slashes (directly after the TLD)
RewriteCond %{THE_REQUEST} \s/{2,}
RewriteRule (.*) $1 [R=301,L]
# Rule 2: remove multiple slashes in the requested path
RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
RewriteRule (.*) %1/%2 [R=301,L]
</IfModule>

 

Rule 1: {THE_REQUEST} contains something like GET /index.html HTTP/1.1

Hence, if we match the first whitespace (\s) followed by multiple slashes (/{2,}), we can access the correct URL without the leading double slash via $1.

Rule 2: The regular expression ^(.*)/{2,}(.*)$ splits the request URI on multiple slashes. %1/%2 then combines the two splitted strings again, but with only one slash at this time.

So for example, this directive will redirect as follows:

  • https://www.meysmahdavi.com// redirects to https://www.meysmahdavi.com/
  • https://www.meysmahdavi.com//blog-post/ redirects to https://www.meysmahdavi.com/blog-post/
  • https://www.meysmahdavi.com//path/directory/ redirects to https://www.meysmahdavi.com/path/directory/

So basically it removes the double slashes from any URL.

Logically, this code is doing the following:

  • Check if the Apache module, mod_alias, is available
  • A 301 server response code is specified and will be sent if a redirect happens
  • Regex matches two forward slashes // included at the beginning ^ of the request
  • Regex then matches any characters or no characters (.*)
  • Regex matches the end of the request string $
  • If a URL is matched, it is redirected to the specified URL
  • Any characters matched via (.*) are appended to the URL via $1 $2

That’s all there is to it. The only edit that’s required is the domain name, simply replace https://www.meysmahdavicom with your own domain and you’re good to go. Don’t forget to always test thoroughly.

We used this code you can test:

https://www.meysmahdavi.com////blog

Remove / from the end of WordPress links using .htaccess file

In this WordPress tutorial, we want to provide you with a simple and short, but practical way to remove slash (/) from all links on your site.

Of course, all sites are so expanded that all of them may have links with an / at the end. But today we will show you how you can get rid of them all using a short code snippet.

Be extremely careful when using this code. In some content management systems (cms) such as WordPress, especially after installing SEO plugins, the slash / sign is always at the bottom of the site pages link and it is not necessary to delete it, but it is better to do so.

Therefore, by redirecting the address with slash to the address without slash, we prevent such problems. To do this, just copy the following code into the .htaccess file in WordPress.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpg|png|jpeg|css|js)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

In the above code, the formats gif | jpg | png | jpeg | css | js are excluded from removing the slash from the bottom of the link. You can add more formats if needed.

حذف / از انتهای لینک های وردپرس با استفاده از فایل htaccess

در این نوشته از آموزش وردپرس میخواهیم به شما روشی ساده و کوتاه، اما کاربردی برای حذف اسلش (/) از تمامی لینک های سایتتان ارائه کنیم.

قطعا تمامی سایت ها به قدری گسترش و توسعه پیدا میکنند که در تمامی آنها ممکن است لینک هایی وجود داشته باشد که در انتهای آنها یک / اضافه، موجود باشد. اما امروز به شما نشان خواهیم داد که چگونه میتوانید با استفاده از یک قطعه کد کوتاه، تمامی انها را از بین ببرید.

در استفاده از این کد نهایت دقت را داشته باشید. در برخی سیستم های مدیریت محتوا (cms) نظیر وردپرس، به ویژه پس از نصب افزونه های سئو ساز، همواره علامت اسلش / در انتهای لینک صفحات سایت قرار دارد و الزامی به حذف آن نیست، اما بهتر است که این کار انجام شود.

از این رو با ریدایرکت کردن آدرس با اسلش بر روی آدرس بدون اسلش، از بروز چنین مشکلاتی پیشگیری می کنیم. برای انجام این کار، کافیست کد زیر را در فایل .htaccess موجود در وردپرس کپی کنید.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpg|png|jpeg|css|js)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

در کد فوق، فرمت های gif|jpg|png|jpeg|css|js از حذف اسلش از انتهای لینک استثناء قائل شده است. در صورت نیاز می توانید فرمت های بیشتر را اضافه نمایید.

دستورات کاربردی htaccess

فایل htaccess چیست؟

.htaccess فایل های htaccess. جهت تغییر پیکربندی نرم افزار سرور آپاچی وب استفاده می شود که امکان فعال سازی و یا غیر فعال سازی قابلیت های اضافی و ویژگی های وب سرور آپاچی را فراهم می کند.

آموزش htaccess، ایت و مدیریت بهینه وردپرس با آن

در صورتیکه تمایل دارید تنظیمات روی تمام فولدرهای سایت اعمال شود ، از فایل htaccess موجود در فولدر public_html استفاده کنید. فایل htaccess ، در سرور به صورت فایل مخفی (Hidden) هست.

محافظت از فایل .htaccess :

برای جلوگیری از سرقت اطلاعات خود فایل htaccess کد زیر را در ابتدای فایل htaccess قرار دهید:

<files ".htaccess">
order allow,deny
deny from all
</files>

جلوگیری از سرقت فایلهای و فولدرهای دران هاست :

بیشتر وقتها اطلاعاتی مثل فایل‌های قالب اختصاصی که بر روی هاست قرار دارند و یا فایل‌هایی که به صورت zip شده در هاست خود ذخیره کرده‌اید به راحتی کشف و به سرقت می رود. برای جلوگیری از این امر کد زیر را در انتهای فایل htaccess قرار دهید.

Options All -Indexes

معرفی زبان پیشفرض (DefaultCharset) :

جهت تعیین زبان پیش‌فرض استفاده شده در مرورگرها، کدهای زیر را در قسمت هدر سایت قرار دهید. این عمل تاثیر خوبی روی سئو (SEO) سایت نیز دارد.

# pass the default character set
AddDefaultCharset utf-8

تعیین صفحات سفارشی روی صفحات خطا :

با دستور زیر می توانید برگه‌هایی را که جهت نمایش هنگام ایجاد خطا، طراحی و در پوشه error قرار دارند را جایگزین صفحات خطای پیش‌فرض کنید. معرفی و تعیین صفحات خطا روی سئو سایت تاثیر خوبی دارد.

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

نمونه ای از چند خطای آپاچی ( Apache):

  • خطای 401 : دسترسی به آدرس وارد شده غیر مجاز است.
  • خطای 403: دسترسی به آدرس ممنوع می‌باشد.
  • خطای 404: آدرس مورد نظر یافت نشد.
  • خطای 500: خطای داخلی سرور بوجود آمده است.

فیلترینگ (banned) اسپمرها با .htaccess (محدودیت دسترسی از طریق IP)

با توجه به بالا بودن میزان دیدگاه‌های اسپم مخصوصا روی سایت های پربازدید، بهتر است ترجیحا آی پی آنها را مسدود نمایید.

<Limit GET POST>
order allow,deny
deny from 200.49.176.139
allow from all
</Limit>

دستور “allow from all” بدین معناست که همه آی‌پی‌ها بجز آی‌پی‌های مسدود شده دسترسی دارند. اگه بخواهید فقط به IP‌های خاصی اجازه دسترس دهید کافی است به کدی نظیر “allow from IP” را نوشته و به جای IP ، آی پی مورد نظر خود را وارد کنید.

با دستور “deny from IP” هم اجازه دسترسی آن آی پی را محدود می نمایید. همچنین می توانید هر تعداد IP زیرهم اضافه کنید. با این کد هیچ آی پی دسترسی نخواهد داشت.

نکته: از دیدگاه برخی از برنامه نویسان قرار دادن “<Limit GET POST>” و “</Limit>” در ابتدا و انتهای تعیین دسترسی‌ها مشکلاتی را ایجاد می‌کند که شما می توانید آنها از ابتدا و انتهای کدها بردارید.

جلوگیری از ارسال دیدگاه اسپم در وردپرس :

افزونه اکیسمت افزونه شناخته شده‌ای در زمینه جلوگیری از ارسال اسپم هست که در بسته اصلی خود وردپرس هم وجود دارد، اما می توانید با استفاده از کد زیر از ارسال هرزنامه به وبسایتتان جلوگیری کنید. دقت داشته باشید که در خط چهارم بجای yourblog.com آدرس سایت خود را وارد کنید.

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

حذف category از آدرس سایت وردپرسی :

ممکن است بخواهید عبارت /category/ را از آدرس سایت وردپرسی خود حذف کنید. این کار علاوه بر اینکه باعث کوتاه شدن شدن url می شود تاحدودی هم در سئو سایت موثر هست.

RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

تغییر عنوان و پسوند فایل پیش‌فرض index در هنگام بارگذاری :

حتما تا حالا دقت نمودید که در هنگام فراخوانی یک آدرس، فایل های پیش فرض نظیر index.html یا index.php بارگزاری می شوند .

بطور مثال در صورت نیاز به تغییر فایل پیش فرض، با قرار دادن کد زیر هنگام فراخوانی به دنبال file.php میگردد و در صورت پیدا نکردن آن، به دنبال file.html خواهد بود.

DirectoryIndex file.php file.html

سایت با www یا بدون www :

در صورتی که در سایت خود، هم از www و هم بدون www استفاده می کنید ، این کار تاثیر منفی روی سئو داشته و اعتبار سایت شما در موتور های جستجو بشدت کاهش می یابد.

جهت استفاده از سایت بدون www، می توانید از خطوط زیر استفاده نمایید:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]

جهت استفاده از سایت با www، می توانید از خطوط زیر استفاده نمایید:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

بالا بردن امنیت فایل wp-config.php در htaccess:

جهت جلوگیری از سرقت اطلاعات حیاتی و جلوگیری از دسترسی به اطلاعات پایگاه داده سایت (Database) کد زیر را در فایل htaccess قرار دهید .

<files wp-config.php>
order allow,deny
deny from all
</files>

مخفی کردن فرمت ها/شناساندن فرمت‌های جدید (add mime type) :

یک راه امنیتی که جهت حفاظت از اسکریپت‌های PHP پیشنهاد می شود این هست که آنها PHP نباشند. برای مثال: فایل PHP شما با فرمت ASP باز شود.

AddType application/x-httpd-php .asp .jsp

فرض کنید می‌خواهید از shtml/ssl در سایتتون استفاده کنید و نیاز به شناساندن این فرمتها به آپاچی دارید در این صورت از مشابه کدهای زیر استفاده نمایید :

AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes

ریدایرکت (Redirect):

جهت اینکار از کدهای زیر استفاده نمایید :

Redirect /Dirold/old.html http://meysmahdavi.com/DirNew/new.html

محدود کردن نوع فایلهای قابل اجرا و نمایش :

برای حفظ امنیت و اطلاعات سایت می‌توانید پسوند فایل‌هایی را تعیین کنید :

Options +FollowSymlinks
RewriteEngine On
rewritecond %{REQUEST_FILENAME} !^(.+).css$
rewritecond %{REQUEST_FILENAME} !^(.+).js$
rewritecond %{REQUEST_FILENAME} !file.php$
RewriteRule ^(.+)$ /deny/ [nc]

با کد بالا کاربر فقط اجازه باز کردن فایل هایی با پسوند css , js و php رو داشته و در صورت درخواست سایر پسوندها به پوشه deny. ریدایرکت می شود.

ایجاد محدودیت در آپلود فایل :

با کد زیر می توان حداکثر حجم فایل قابل آپلود را تنظیم نمود.

php_value upload_max_filesize 20M

ایجاد محدودیت در حجم پست ارسالی :

با کد زیر می توان حداکثر حجم هر پست را تعیین کرد.

php_value post_max_size 2M

نمایش پیغام requast time در بازه زمانی مشخص :

requast time به معنای حداکثر زمان درخواست فراخوانی یک صفحه هست و با کد زیر میتوان آن را تغییر داد :

php_value max_execution_time 200

حداکثر زمان دریافت اطلاعات POST و GET :

php_value max_input_time 250

جلوگیری از سرقت پهنای باند، فایل‌ها و عکس‌ها :

گاها مدیران سایت‌های دیگر آدرس عکس یا فایل‌های شما را کپی کرده و در سایت خودشون استفاده می کنند. با این عمل در حقیقت در هنگام نمایش سایت آنها، درخواستی نیز به سرور شما جهت باز نمودن عکس ارسال میشود و در نهایت ار پهنای باند شما نیز کاسته میشود. جهت جلوگیری از این کار و ایجاد محدودیت برای نمایش فایل‌ها کد زیر را در فایل htaccess قرار دهید:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?site.com/ .*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

فعال کردن قابلیت Gzip :

زمانی که کاربر از طریق مرورگر درخواست نمایش سایت شما رو میدهد، این درخواست به سرور شما ارسال شده و سرور فایل‌هایی که برای نمایش سایت شما لازم است را آماده کرده و به مرورگر کاربر میفرستد و در نتیجه سایت نمایش داده میشود، ولی اگر از قابلیت Gzip استفاده کنید، هنگام درخواست، سرور فایل‌های مورد نیاز را به صورت فشرده درآورده و این فایل فشرده را به مرورگر ارسال میکند و و بعد از خارج شدن از حالت فشرده در سیستم کاربر سایت نمایش داده میشود.

در حقیقت میزان حجمی که باید توسط مرورگر برای نمایش سایت دریافت شود، کمتر میشود و این به معنای افزایش قابل توجه سرعت بارگزاری سایت می شود.

در صورتی که سرور از این قابلیت پشتیبانی میکند، مشابه کد زیر را برای فعال شدن این قابلیت روی سایت خود در فایل htaccess قرار دهید.

# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php|woff|ttf|png|jpg|gif)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files

مدیریت Cache فایلها :

کش بدین معناست که فایلهای سایت شما که طی مدت خاصی تغییر نکردند و یا در فواصل زمانی زیاد دچار تغییرات قرار میگرند را در یک حافظه نسبتا امن در مرورگر کاربر ذخیره نموده تا در دفعات بعدی مراجعه به سایت، این فایلها از سیستم کاربر بارگزاری شوند و در نهایت سرعت بارگزاری سایت چندین چند برابر می شود.

# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf|woff|ttf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "max-age=2592000, private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off
# BEGIN Remove Last-Modified Header
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
# END Remove Last-Modified Header

حل مشکل تعداد آیتم های فهرست وردپرس :

ممکن است برای شما هم اتفاق افتاده باشد که هنگام ساخت فهرست دسته‌ها به صورت دستی در وردپرس، از جایی به بعد هر فهرستی اضافه میکنید، اضافه نشود. برای حل محدودیت کد زیر را در فایل htaccess قرار دهید:

<IfModule mod_php.c>
php_value suhosin.post.max_vars 7000
php_value suhosin.request.max_vars 7000
</IfModule>

-افزایش امنیت محتوای فولدر wp-includes :

جهت این کار کافی است کد زیر را در htaccess قرار دهید :

# Block the include-only files.
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]