How about working with a team that puts the worries of the virtual environment aside and makes this burden more attractive to you with its wide range of services?
Contact Now: +90 850 305 25 95
E-mail:info@margarit.com.tr
Address: İvoksan, Neva Home Offices
1455 Street, 22/41 Yenimahalle / Ankara

Using htaccess and 301 Redirect Rules (Php, WordPress)

margarit-web-reklam-bilisim-2020

Do you have a website and are happy to move it to a different directory, subdirectory, subdomain or a different URL address?

At the same time, do you want the hits coming to your site to not be lost during the migration process, and the URL addresses to be redirected to the address you just moved without turning into a 404 error? You can easily apply this redirect gesture as a permanent action with the 301 Redirect activity.

What is htaccess file? What does htaccess do?

If you work with CMS systems such as WordPress, Joompla and Drupal after server and hosting installations, you must have witnessed the existence and essential functionality of this file.

The htaccess file, or HyperText Access file, is an essential server routing function, where directory checks are made within the structure. In order to make your server's file layout functional after Apache server installations, your htaccess arrangement must be in the structure you want.

301 Redirection, which is a permanent redirect function where you can come across millions of alternative articles on the web as 301 Redirection, is carried out with simple but vital codes that you add to the htaccess file.

What Are Commonly Used Htaccess 301 Redirect Rules?

If you want to redirect a single page with htaccess and 301 Redirect

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

Redirecting a domain or main address to a completely new one with htaccess and 301 Redirect

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

Redirecting a subdirectory site to another home address with htaccess and 301 Redirect

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

Redirecting the same address to a different file format without changing the filename with htaccess and 301 Redirect

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

Redirecting old address to new with rewrite method with htaccess and 301 Redirect

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

Redirecting non-www site to www version with htaccess and 301 Redirect

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

Redirecting non-www site to new address with ww and subdirectory with htaccess and 301 Redirect

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

Redirecting a domain or home address completely and without breaking the same link structure with htaccess and 302 Redirect

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

A redirect without subdirectory with htaccess and 302 Redirect without breaking the site in a subdirectory completely and without breaking the same link structure

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

Moving a site in a directory to a new directory with query extensions with htaccess and 301 Redirect

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

Convert HTTP site to HTTPS version without duplication with htaccess and 301 Redirect

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

If you want to recover from HTTP while doing HTTPS redirect with htaccess and 301 Redirect

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

Recovering from index.php or index.html structures with htaccess and 301 Redirect, redirecting to the main address

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

Recovering from the index query with htaccess and 301 Redirecting and directing it as an address

Example: Direct redirect from https://www.margarit.com.tr/index.php?id=100 to https://www.margarit.com.tr/100/

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

Recovering from the index query with htaccess and 301 Redirecting and directing it as a direct address with subdirectory definition

Example: Direct redirect from https://www.margarit.com.tr/index.php?kategori=kes to https://www.margarit.com.tr/categorie/cats

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

Moving a site completely to a new one without breaking the URL structure with htaccess and 301 Redirect

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]

Redirect from sub domain to subdirectory with htaccess and 301 Redirect

Example: Direct redirect from blog.margarit.com.tr to https://www.margarit.com.tr/blog/

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

Redirecting a subdirectory to another subdirectory with htaccess and 301 Redirect rules

Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $1/new-directory/$2 [R,L]

You want to move the system in a domain completely to a subdirectory and you want the incoming hits to be directed directly to the url in the subdirectory.

RewriteEngine on Options +FollowSymLinks RewriteCond %{HTTP_HOST} ^margarit.com$ [OR] RewriteCond %{HTTP_HOST} ^www.margarit.com$ RewriteRule ^(.*)$ "https://www.marumgarit"TP3T. [R=301,L]
No Comments
Post a comment

en_USEnglish