مرکز آموزش

  1. Redirect Rule (قواعد ریدایرکت) عمومی به صورت 301 در فایل .htaccess

Redirect Rule (قواعد ریدایرکت) عمومی به صورت 301 در فایل .htaccess

اعضا > مرکز آموزش > پشتیبانی میزبانی وب و ثبت دامین > سوالات عمومی > Redirect Rule (قواعد ریدایرکت) عمومی به صورت 301 در فایل .htaccess

There are common htaccess 301 redirect rules that I find myself searching for each time I build a website, redirect a page for an SEO strategy for a client, or help with a website’s SEO transition plan. So I thought I would create a resource where I could gather all the common rules into one spot to save me time for each project.

What is an Htaccess file? The .htaccess, or Hypertext Access file, is a configuration text file that controls the directory and any subdirectories located on an Apache webserver. If you use a Linux-based web hosting plan, your web properties likely run on Apache. You may have seen the .htaccess file in certain directories, particularly if you have deployed WordPress, Joomla, Drupal, or any other content management web software.

The .htaccess file can include specific instructions to the server. This file can configure the server to require a password for the directory where it resides. The .htaccess file can also be configured to automatically redirect users to another index file or site, restrict or allow users based on IP addresses, and disable directory listings. You may never need to edit the .htaccess file, but if you do, you must make sure that the file is named ‘.htaccess’ only, with the period in front and no .txt or .htm file extension.

Common 301 Redirect Htaccess Rules

چگونه یک صفحه را ریدایرکت کنیم؟

Redirect 301 /pagename.php http://www.domain.com/pagename.html

چگونه یک وب سایت یا دامین را به آدرس جدید ریدایرکت کنیم؟

Redirect 301 / http://www.domain.com/

چگونه یک وب سایت را به یک فولدر داخلی ریدایرکت کنیم؟

Redirect 301 / http://www.domain.com/subfolder/

چگونه یک فولدر داخلی را به یک وب سایت دیگر ریدایرکت کنیم؟

Redirect 301 /subfolder http://www.domain.com/

چگونه یک فایل با پسوند را به همان نام به یک پسوند دیگر ریدایرکت کنیم؟ Example: If you want a .html extension to use the same filename but use the .php extension.

RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php

چگونه یک دامین را از نام قدیمی به نام جدید ریدایرکت کنیم؟

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

چگونه یک دامین را از بدون WWW به حالت با WWW ریدایرکت کنیم؟

RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

چگونه یک دامین بدون WWW را به یک آدرس ساب فولدر داخلی با WWW ریدایرکت کنیم؟

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/directory/index.html [R=301,NC]

چگونه یک دامین قدیمی را به یک دامین جدید به آدرس کامل و Query String ها ریدایرکت کنیم؟

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

How do you use rewriting to redirect from an old domain with a subdirectory to a new domain without the subdirectory but include the full path and query string?

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC]

How do you rewrite and redirect URLs with query parameters with files placed in a root directory? Example: The original URL being http://www.website.com/index.php?id=3 and the new URL being http://www.website.com/path-to-new-location/

RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^index\.php$ /path-to-new-location/? [L,R=301]

How do you redirect URLs with query parameters and place files in a subdirectory? Example: The original URL being http://www.website.com/sub-dir/index.php?id=3 and the new page being http://www.website.com/path-to-new-location/

RewriteEngine on
RewriteCond %{QUERY_STRING} id=3
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]

چگونه وب سایت را به HTTPS از HTTP ریدایرکت کنیم؟

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

چگونه وب سایت را به HTTP از HTTPS ریدایرکت کنیم؟

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

چگونه index.html یا index.php را حذف کنیم و به مسیر اصلی ریدایرکت کنیم؟

RewriteEngine On
RewriteCond %{THE_REQUEST} /index.php HTTP [NC]
RewriteRule (.*)index.php$ /$1 [R=301,L]
RewriteEngine On
RewriteCond %{THE_REQUEST} /index.html HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]

How do you rewrite and redirect URLs with query parameters to a directory-based structure while retaining the query string in the URL root level? Example: The original URL being http://www.website.com/index.php?id=100 and the new page being http://www.website.com/100/

RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]

How do you rewrite URLs with a query parameter to a directory-based structure while retaining query string parameters in the URL subdirectory? Example: The original URL is http://www.website.com/index.php?category=fish and the new page being http://www.website.com/category/fish/

RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]

چگونه یک دامین را از نام قدیمی به نام جدید به حفظ آدرس کامل ریدایرکت کنیم ؟

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]

If you do not want to pass the path to the new domain, change the last line to:

RewriteRule ^(.*)$ http://www.example-new.com/ [R=301,L]

How do you rewrite and add a trailing slash to URLs without one?

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ^(.*)$ http://www.example.com/$1/ [R=301,L]

How do you redirect from a blog subdomain to a blog folder? Example: Redirect blog.oldsite.com to www.newsite.com/blog/

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.somewhere.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www.somewhere.com/blog/%{REQUEST_URI} [R=302,NC]

How do you redirect one directory to another?

Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $1/new-directory/$2 [R,L]
آیا این پاسخ به شما کمک کرد؟
0 کاربر این را مفید یافتند 0 نظرات

در همین زمینه