Although it is easy to set up a site on WordPress, you may miss links that negatively affect the user experience while managing your content. Error links with 404 codes can be easily found manually and through WordPress. Additionally, you can monitor the e-mails sent by WordPress and review any problems with your site. To fix incorrect codes, I have compiled the fastest 301 redirect methods in WordPress for you.
What is 301 Redirect?
301 code is one of the http status codes. 301 redirect is the name given to redirecting a page from its old URL to its new URL using the 301 code. It is mostly used when the url of the page changes or its content is moved. It has an important place in the SEO process. Below you can find comprehensive examples of sample 301 redirects.
Simple 301 Redirect
Simple 301 redirection is accomplished with the following code written in the .htaccess file in the root directory of your site.
Redirect 301 /eski-sayfanizin-relative-urlsi/ https://www.domainadresiniz.com/yeni-sayfanizin-absolute-urlsi/If your site has a panel or you are using ready-made cms/software, it is possible to achieve this process without writing code via the redirects menu in your panel. To give an example for the WordPress infrastructure, 301 redirects in WordPress can be done by Rank Math SEO, Yoast SEO, All in One SEO and similar SEO plugins without the need to write code. However, for complex redirects, it may be necessary to write special code in the .htaccess file. As examples of complex redirects, we will share the codes we wrote for the most frequently needed redirects.
Redirecting All Query Parameters with 301
# BEGIN: Redirect non-critical query parameters to the current page with 301 redirect by Onur Özden Web Çözümleri
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(.*)wp-admin(.*)
RewriteCond %{REQUEST_URI} !(.*)wp-login(.*)
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|webp|avif|tiff|pdf|mp4|avi|mkv|flv|zip|rar|docx|doc|xlsx|csv|txt|rtf|xml|css|js) [NC]
RewriteCond %{QUERY_STRING} .
RewriteRule ^ %{REQUEST_URI}? [L,R=301]
</ifmodule>
# END: Redirect non-critical query parameters to the current page with 301 redirect by Onur Özden Web ÇözümleriYou can redirect all query parameters back to the current url with the codes above. In the sample code, WordPress' special pages such as the default login page and admin page and some special file types are excluded. You can make adjustments to exclusions as needed.
Htaccess HTTPS and WWW Redirection
Opening the pages as http because they are not directed to the https version even though they have SSL, and publishing the same version of the page without www even though www is used on the site is a big problem not only for technical reasons but also in terms of SEO and user experience. To solve this problem, you can redirect http urls to https with the codes below and ensure that the page opens only with www.
# BEGIN: Redirect All Urls to WWW with 301 redirect by Onur Özden Web Çözümleri
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1/ [R=301,L]
</ifmodule>
# END: Redirect All Urls to WWW with 301 redirect by Onur Özden Web ÇözümleriThe .htaccess file is automatically created with the WP permalink structure. If you can't find the file, you can create one manually via ftp or the hosting control panel:
- Open Notepad. (or whatever code editor you use)
- Paste the relevant code.
- Make the file extension .htaccess instead of .txt, which is short for text, and do not specify a name.
- Add the file you created to the root directory of your site (this directory is often called public_html or htdocs).
With this method, you can perform HTTPS and WWW redirection with .htaccess.
Htaccess HTTPS Redirect
If you do not use www on your site and only want to make HTTP URLs https, simply add these codes we wrote for you to the root directory of your site.
# BEGIN: Redirect All Urls to https and non-www with 301 redirect by Onur Özden Web Çözümleri
<ifmodule mod_rewrite.c>
# Skip it if the url is correct
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* - [L]
# https and non-www redirect
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ https://%{HTTP_HOST}/%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}/%{REQUEST_URI} [R=301,L]
</ifmodule>
# END: Redirect All Urls to https and non-www with 301 redirect by Onur Özden Web ÇözümleriDomain Forwarding
Domain forwarding, in Turkish, is the name given to redirecting the domain and all its URLs to a new domain. You can redirect all URLs in the old domain to the new domain with the code below. Do not forget to replace olddomain and newdomain values and domain extensions with the name of the old and new domain.
# BEGIN: Redirect All Old Domain Urls to New Domain Urls with 301 Redirect by Onur Özden Web Çözümleri
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^(.*)$ "https\:\/\/www\.newdomain\.com\/$1" [R=301,L]
</ifmodule>
# END: Redirect All Old Domain Urls to New Domain Urls with 301 Redirect by Onur Özden Web ÇözümleriHtaccess AMP Redirect
If you used AMP on your site for a while and then removed it, your links edited by AMP may have been indexed in search engines. After removing AMP, you need to redirect these links back to their current state. Otherwise, links with the amp query parameter on the search engine results page will return 404 and the user cannot access the content. Changing the URL with amp to without amp is called "amp to non-amp redirect". You can use the codes below to make this redirect using a 301 code.
# BEGIN: AMP to NON-AMP Redirect for All Known AMP Variations by Onur Özden Web Çözümleri
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} amp [OR,NC]
RewriteCond %{QUERY_STRING} noamp=mobile [OR,NC]
RewriteCond %{QUERY_STRING} amp=1 [NC]
RewriteRule ^ %{REQUEST_URI}? [L,R=301]
RewriteCond %{REQUEST_URI} (.+)/amp(.*)$ [NC]
RewriteRule ^ %1/ [R=301,L]
</ifmodule>
# END: AMP to NON-AMP Redirect for All Known AMP Variations by Onur Özden Web ÇözümleriWordPress Htaccess File
If your htaccess file in WordPress is corrupted and the default codes added by the WordPress system are lost, you can have the htaccess codes added again by clicking Settings > Permalinks > Save. If you do not have access to your admin panel, you can open the .htaccess file in the root directory of your site and enter the following codes. These codes are only valid for WordPress sites installed in the main directory of the subdomain and domain. If your site is installed in a subfolder, you should use the codes in the next heading.
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPressHtaccess Codes for WordPress in Subfolder
If your htaccess file in WordPress is corrupted and your site is installed in a subfolder instead of the main directory or subdomain, you can use the codes below by adding them to the .htaccess file in the root directory of the site. In the codes, do not forget to replace the "subfolder" part with the name of the subfolder where you installed WordPress and the "example.com" part with your domain.
# BEGIN WordPress
<ifmodule mod_rewrite.c>
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]
</ifmodule>
# END WordPressYou can perform your redirection process with best practice by using the redirect codes created for the most common situations that we have prepared for you in your .htaccess file.
Frequently Asked Questions
What is WordPress 301 redirect?
WordPress 301 redirect is the name given to redirecting pages on your site whose URL has changed, are no longer used or have been moved, to another relevant page. 301 redirect takes its name from the 301 code, which is the HTTP status code.
What is htaccess 301 redirect?
301 .htaccess redirection is the process of performing 301 redirection by writing redirect codes into the .htaccess file. htaccess file is used, it is called "htaccess 301 redirect".
How to do WordPress 301 redirect?
You can do WordPress 301 redirection without needing code knowledge by using SEO plugins such as Rank Math SEO, Yoast SEO, All in One SEO or redirection plugins such as Redirection, 301 Redirect.



