{"id":2827,"date":"2019-10-06T05:21:57","date_gmt":"2019-10-06T05:21:57","guid":{"rendered":"https:\/\/servervds.com\/?p=2827"},"modified":"2019-10-06T05:21:57","modified_gmt":"2019-10-06T05:21:57","slug":"mod_rewrite-in-apache-and-its-examples","status":"publish","type":"post","link":"https:\/\/servervds.com\/mag\/mod_rewrite-in-apache-and-its-examples\/","title":{"rendered":"mod_rewrite \u062f\u0631 \u0622\u067e\u0627\u0686\u06cc \u0648 \u0645\u062b\u0627\u0644\u0647\u0627\u06cc \u0622\u0646"},"content":{"rendered":"\n<h2>mod_rewrite \u0686\u06cc\u0633\u062a\u061f<\/h2>\n\n\n\n<p>servervds \u0628\u0631\u0627\u06cc \u0645\u06cc\u0632\u0628\u0627\u0646\u06cc \u0648\u0628 \u0633\u0627\u06cc\u062a \u0634\u0645\u0627 \u0627\u0632 Apache \u060c \u0646\u0631\u0645 \u0627\u0641\u0632\u0627\u0631 \u0645\u0646\u0628\u0639 \u0628\u0627\u0632 HTTP \u0633\u0631\u0648\u0631 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u062f. \u0622\u067e\u0627\u0686\u06cc \u0631\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646 \u0627\u0632 \u0637\u0631\u06cc\u0642 \u0645\u0627\u0698\u0648\u0644 \u0647\u0627 \u0633\u0641\u0627\u0631\u0634\u06cc \u0633\u0627\u0632\u06cc \u06a9\u0631\u062f \u0648 \u0645\u0627\u0698\u0648\u0644 mod_rewrite \u0628\u0631\u0627\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u062f\u0631 \u0627\u062e\u062a\u06cc\u0627\u0631 \u0634\u0645\u0627 \u0642\u0631\u0627\u0631 \u0645\u06cc \u06af\u06cc\u0631\u062f. mod_rewrite \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u06cc\u06a9 URL \u0631\u0627 \u0628\u0647 URL \u062f\u06cc\u06af\u0631 \u0647\u062f\u0627\u06cc\u062a \u06a9\u0646\u062f \u060c URL \u0647\u0627\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc \u0631\u0627 \u0628\u0627\u0632\u0646\u0648\u06cc\u0633\u06cc \u06a9\u0646\u062f \u060c \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u0633\u0627\u06cc\u062a \u0634\u0645\u0627 \u0631\u0627 \u0645\u062d\u062f\u0648\u062f \u06a9\u0646\u062f \u0648 &#8230; .<\/p>\n\n\n\n<p>\u0628\u0627 \u0642\u0631\u0627\u0631 \u062f\u0627\u062f\u0646 \u0622\u0646 \u062f\u0631 \u067e\u0631\u0648\u0646\u062f\u0647 .htaccess \u060c \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u0627\u0632 \u0642\u0627\u0646\u0648\u0646 \u0628\u0627\u0632\u0646\u0648\u06cc\u0633\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u062f. \u062f\u0631 \u0632\u06cc\u0631 \u0646\u0645\u0648\u0646\u0647 \u0647\u0627\u06cc\u06cc \u0627\u0632 \u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u06cc\u0646 \u0642\u0648\u0627\u0646\u06cc\u0646 \u0628\u0631\u0627\u06cc \u0634\u062e\u0635\u06cc \u0633\u0627\u0632\u06cc \u062a\u062c\u0631\u0628\u0647 \u0645\u06cc\u0632\u0628\u0627\u0646\u06cc \u062e\u0648\u062f \u0622\u0648\u0631\u062f\u0647 \u0634\u062f\u0647 \u0627\u0633\u062a.<\/p>\n\n\n\n<h2>\u0645\u062b\u0627\u0644\u0647\u0627\u06cc mod_rewrite<\/h2>\n\n\n\n<p>\u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0646\u0645\u0648\u0646\u0647 \u0647\u0627\u06cc\u06cc \u0627\u0632 \u0642\u0648\u0627\u0646\u06cc\u0646\u06cc \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f \u06a9\u0647 \u0628\u0647 \u0634\u0645\u0627 \u0627\u0645\u06a9\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f \u0645\u0648\u0627\u0631\u062f \u0632\u06cc\u0631 \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u06cc\u062f:<\/p>\n\n\n\n<h3>\u0635\u0641\u062d\u0647 \u0627\u0635\u0644\u06cc \u067e\u06cc\u0634 \u0641\u0631\u0636 \u0631\u0627 \u062a\u0646\u0638\u06cc\u0645 \u06a9\u0646\u06cc\u062f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#Specify a default home page (index page)\nDirectoryIndex home.html<\/code><\/pre>\n\n\n\n<h3>\u062f\u0633\u062a\u0631\u0633\u06cc IP \u0631\u0627 \u0645\u0634\u062e\u0635 \u06a9\u0646\u06cc\u062f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#Allow only specified IPs to access your site\ndeny from all\nallow from 64.95.219.140\nallow from 210.23.45.67<\/code><\/pre>\n\n\n\n<h3>\u0647\u0645\u0647 \u0635\u0641\u062d\u0627\u062a \u0648\u0628 \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u0645\u0633\u06cc\u0631 \u062f\u0647\u06cc\u062f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Redirect all pages from olddomain.com\n# to newdomain.com\nOptions +FollowSymLinks\nRewriteEngine on\nRewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]\nRewriteCond %{HTTP_HOST} ^olddomain.com$\nRewriteRule ^(.*)$ http:\/\/www.newdomain.com\/$1 [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u062c\u0644\u0648\u06af\u06cc\u0631\u06cc \u0627\u0632 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u0632\u06cc\u0631 \u067e\u0648\u0634\u0647<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#Prevent subfolder loading. This goes\n# in htaccess for the primary domain\nRewriteCond %{HTTP_HOST} ^primary\\.com$ [OR]\nRewriteCond %{HTTP_HOST} ^www\\.primary\\.com$\nRewriteRule ^addon\\.com\\\/?(.*)$ \"http\\:\\\/\\\/www\\.addon\\.com\\\/$1\" [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u062c\u0644\u0648\u06af\u06cc\u0631\u06cc \u0627\u0632 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u0632\u06cc\u0631 \u062f\u0627\u0645\u0646\u0647<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#Prevent subdomain name loading.\n#This goes in htaccess for the primary domain\nRewriteCond %{HTTP_HOST} ^subname\\.primary\\.com$ [OR]\nRewriteCond %{HTTP_HOST} ^www\\.subname\\.primary\\.com$\nRewriteRule ^(.*)$ \"http\\:\\\/\\\/www\\.addon\\.com\\\/$1\" [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u062f\u0627\u0645\u0646\u0647 \u0628\u062f\u0648\u0646 www<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Never use www in the domain\n# Replace 'example.com' with your domain name\nRewriteEngine on\nRewriteCond %{HTTP_HOST} ^www\\.(([a-z0-9_]+\\.)?example\\.com)$ [NC]\nRewriteRule .? http:\/\/%1%{REQUEST_URI} [R=301,L]<\/code><\/pre>\n\n\n\n<h3 id=\"mce_100\">\u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u062f\u0627\u0645\u0646\u0647 \u0628\u0627 www<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Always use www in the domain\n# Replace 'example.com' with your domain name\nRewriteEngine on\nRewriteCond %{HTTP_HOST} ^([a-z.]+)?example\\.com$ [NC]\nRewriteCond %{HTTP_HOST} !^www\\. [NC]\nRewriteRule .? http:\/\/www.%1example.com%{REQUEST_URI} [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u062a\u0646\u0638\u06cc\u0645 \u067e\u0648\u0634\u0647 \u067e\u06cc\u0634 \u0641\u0631\u0636 \u062e\u0627\u0646\u0647<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Set a default home directory, (this subfolder always loads)\n# Replace 'folder' with your subfolder name\n&lt;IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteRule ^$ \/folder\/ [R=301,L]\n&lt;\/IfModule><\/code><\/pre>\n\n\n\n<h3>\u062a\u063a\u06cc\u06cc\u0631 \u0645\u0633\u06cc\u0631 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u067e\u0648\u0634\u0647<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Rename a directory and force visitors to the new name\n# Replace 'old' with your old folder name\n# Replace 'new' with your new folder name\nRewriteEngine on\nRewriteRule ^\/?old([a-z\/.]*)$ \/new$1 [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u0627\u062c\u0628\u0627\u0631\u06cc \u06a9\u0631\u062f\u0646 \u0644\u0648\u062f \u0628\u0627 https<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Always use https for secure connections\n# Replace 'www.example.com' with your domain name\n# (as it appears on your SSL certificate)\nRewriteEngine On\nRewriteCond %{SERVER_PORT} 80\nRewriteRule ^(.*)$ https:\/\/www.example.com\/$1 [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u0645\u0633\u062f\u0648\u062f \u06a9\u0631\u062f\u0646 \u0686\u0646\u062f \u0645\u0631\u0627\u062c\u0639\u0647 \u06a9\u0646\u0646\u062f\u0647 \u062a\u0631\u0627\u0641\u06cc\u06a9<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Block traffic from multiple referrers\nRewriteEngine on\nOptions +FollowSymlinks\nRewriteCond %{HTTP_REFERER} badsite\\.com [NC,OR]\nRewriteCond %{HTTP_REFERER} badforum\\.com [NC,OR]\nRewriteCond %{HTTP_REFERER} badsearchengine\\.com [NC]\nRewriteRule .* - [F]<\/code><\/pre>\n\n\n\n<h3>\u0628\u0633\u062a\u0646 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u0646\u0648\u0639 \u062e\u0627\u0635\u06cc \u0627\u0632 \u0641\u0627\u06cc\u0644 \u0647\u0627<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#Do not allow these file types to be called\nRewriteEngine on\nRewriteRule .*\\.(jpg|jpeg|gif|png|bmp|exe|swf)$ - [F,NC]<\/code><\/pre>\n\n\n\n<h3>\u062d\u0630\u0641 Index<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Options +FollowSymLinks -MultiViews -indexes\nRewriteEngine On\nRewriteBase \/\n# remove index\nRewriteCond %{THE_REQUEST} \/index(\\.php)?[\\s?\/] [NC]\nRewriteRule ^(.*?)index(\/|$) \/$1 [L,R=301,NC,NE]<\/code><\/pre>\n\n\n\n<h3>\u062d\u0630\u0641 .php<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Options +FollowSymLinks -MultiViews -indexes\nRewriteEngine On\nRewriteBase \/\n# remove .php; use THE_REQUEST to prevent infinite loops\nRewriteCond %{THE_REQUEST} ^GET\\ (.*)\\.php\\ HTTP\nRewriteRule (.*)\\.php$ $1 [L,R=301]<\/code><\/pre>\n\n\n\n<h3>\u062d\u0630\u0641 index \u0648 \/<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Options +FollowSymLinks -MultiViews -indexes\nRewriteEngine On\nRewriteBase \/\n# remove index\nRewriteRule (.*)\/index$ $1\/ [R=302]\n# remove slash if not directory\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_URI} \/$\nRewriteRule (.*)\/ $1 [R=301,L]<\/code><\/pre>\n\n\n\n<h3>\u0627\u0636\u0627\u0641\u0647 \u0646\u0645\u0648\u062f\u0647 .php \u0628\u0631\u0627\u06cc \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u0647 \u06cc\u06a9 \u0641\u0627\u06cc\u0644 \u0628\u062f\u0648\u0646 \u0631\u06cc\u062f\u0627\u06cc\u0631\u06a9\u062a<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Options +FollowSymLinks -MultiViews -indexes\nRewriteEngine On\nRewriteBase \/\n# add .php to access file, but don't redirect\nRewriteCond %{REQUEST_FILENAME}.php -f\nRewriteCond %{REQUEST_URI} !\/$\nRewriteRule (.*) $1.php [L]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>mod_rewrite \u0686\u06cc\u0633\u062a\u061f servervds \u0628\u0631\u0627\u06cc \u0645\u06cc\u0632\u0628\u0627\u0646\u06cc \u0648\u0628 \u0633\u0627\u06cc\u062a \u0634\u0645\u0627 \u0627\u0632 Apache \u060c \u0646\u0631\u0645 \u0627\u0641\u0632\u0627\u0631 \u0645\u0646\u0628\u0639 \u0628\u0627\u0632 HTTP \u0633\u0631\u0648\u0631 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u062f. \u0622\u067e\u0627\u0686\u06cc \u0631\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646 \u0627\u0632 \u0637\u0631\u06cc\u0642 \u0645\u0627\u0698\u0648\u0644 \u0647\u0627 \u0633\u0641\u0627\u0631\u0634\u06cc \u0633\u0627\u0632\u06cc \u06a9\u0631\u062f \u0648 \u0645\u0627\u0698\u0648\u0644 mod_rewrite \u0628\u0631\u0627\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u062f\u0631 \u0627\u062e\u062a\u06cc\u0627\u0631 \u0634\u0645\u0627 \u0642\u0631\u0627\u0631 \u0645\u06cc \u06af\u06cc\u0631\u062f. mod_rewrite \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u06cc\u06a9 URL \u0631\u0627 \u0628\u0647 URL \u062f\u06cc\u06af\u0631 \u0647\u062f\u0627\u06cc\u062a \u06a9\u0646\u062f \u060c URL &hellip;<\/p>\n","protected":false},"author":1,"featured_media":4083,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,10,5],"tags":[],"_links":{"self":[{"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/posts\/2827"}],"collection":[{"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/comments?post=2827"}],"version-history":[{"count":0,"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/posts\/2827\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/media\/4083"}],"wp:attachment":[{"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/media?parent=2827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/categories?post=2827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/servervds.com\/mag\/wp-json\/wp\/v2\/tags?post=2827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}