1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

کد ریدایرکت htaccess

نمونه کدهای .htaccess برای ریدایرکت کردن صفحات سایت

 

ریدایرکت دائمی

Permanent redirect from example.com to domain.com


  RewriteEngine On
 RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
 RewriteCond %{HTTP_HOST} ^www\.example\.com$
 RewriteRule ^/?$ "http\:\/\/domain\.com\/" [R=301,L]
 

 

ریدایرکت موقتی

Temporary redirect from example.com to domain.com

 

         RewriteEngine On
 RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
 RewriteCond %{HTTP_HOST} ^www\.example\.com$
 RewriteRule ^/?$ "http\:\/\/domain\.com\/" [R=302,L]
 

 

Redirect from example.com/subfolder to domain.com

         RewriteEngine On
 RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
 RewriteCond %{HTTP_HOST} ^www\.example\.com$
 RewriteRule ^subfolder$ "http\:\/\/domain\.com\/" [R=301,L] 
 

 

Redirect from HTTP to HTTPS

          RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule .* {REQUEST_URI} [R,L]یا RewriteCond %{SERVER_PORT} 80
 RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
 RewriteCond %{HTTP_HOST} ^www\.example\.com$
 RewriteRule ^(.*)$  [R,L] 

 

Redirect from non-WWW to WWW

 

  • for any domain .htaccess takes effect on:
RewriteEngine On
 RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
  • for a certain domain, example.com:
 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
 RewriteRule ^(.*)$  [R=301,L] 

 

Redirect from WWW to non-WWW

 

  • for any domain .htaccess takes effect on:
 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
 RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  • for a certain domain, example.com:
RewriteEngine On
 RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
 RewriteRule (.*)  [R=301,L]

 

 

Changes the directory root for the main domain to public_html/subfolder


  RewriteEngine on
 RewriteCond %{HTTP_HOST} ^(www.)?example.com$
 RewriteCond %{REQUEST_URI} !^/subfolder/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /subfolder/$1
 RewriteCond %{HTTP_HOST} ^(www.)?example.com$
 RewriteRule ^(/)?$ subfolder/index.php [L] 

کد ریدایرکت htaccess

کد ریدایرکت htaccess

آشنایی با کد های .htaccess