Bang hộiTiền mặt: 0 Xu Trò chơiHộp quà giáng sinhThứ Sáu, 08:08:38 - 22/11/2024
Chia sẻ kiến thức ngôn ngữ lập trình C, C++, C#, Java, Python, PHP, JS, SQL ...

Các điều hành viên: Mod, SMod, Admin

How to Change the Default Search URL Slug in WordPress - Thay đổi url tìm kiếm wordpress

How to Change the Default Search URL Slug in WordPress - Thay đổi url tìm kiếm wordpress

#1 » Gửi bài gửi bởi nghiammo1992 » 06/07/2021 01:24 » @522593

Why Change Default Search URL Slug in WordPress

WordPress uses SEO friendly URL structure for all pages on your website. Typical SEO friendly WordPress URLs look like this:

http://gameplay123.com/some-page/
http://gameplay123.com/2018/03/some-article/
http://gameplay123.com/category/some-category/

As you can see, these URLs are quite easy to understand for users as well as search engines.

However, WordPress still uses non-friendly URL for search results page. A typical search URL in WordPress looks like this:

http://gameplay123.com/?s=search-term

This URL structure doesn’t match the rest of your website URLs. While some WordPress search plugins improve the search results, most don’t do anything about the search URL itself.

What if you can make your search URL look like:

http://gameplay123.com/search/your-search-term/

Let’s take a look at how to make the WordPress search page URL slug more SEO friendly.

How to Change the Default Search URL Slug in WordPress - Thay đổi url tìm kiếm wordpress

Method 1. Change WordPress Search URL Slug via Functions File

This method is easier and recommended for most users.

First, you need to copy and paste the following code in your theme’s functions.php file:
Mã: Chọn tất cả
function wpb_change_search_url() {
    if ( is_search() && ! empty( $_GET['s'] ) ) {
        wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
        exit();
    }   
}
add_action( 'template_redirect', 'wpb_change_search_url' );

Don’t forget to save your changes.

You can now go to your website and try using the search feature. You will notice that the search URL looks like this:

http://gameplay123.com/search/mario/

Method 2. Change Search URL Slug via htaccess File

The .htaccess file is often used to set up redirects and other website configuration tasks. You can also use it to change the default search URL slug in WordPress.

Your .htaccess file is located in your website’s root folder, and you will need to use FTP or File Manager app in cPanel to edit it. Refer to this guide, if you can’t find the .htaccess file.

In your .htaccess file, you need to paste the following code at the bottom:
Mã: Chọn tất cả
# Change WordPress search URL
RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]


You can now go to your website and use the search feature. You will notice the search URL will now look like this:

http://gameplay123.com/search/farm/

We hope this article helped you change the default search URL slug in WordPress.

Source: https://www.wpbeginner.com/wp-tutorials/how-to-change-the-default-search-url-slug-in-wordpress/
nghiammo1992 ✅
Hình đại diện của thành viên
Rank: ☀️2/30☀️
Cấp độ:
Tu luyện:
Like:
Online:
Bang hội: Tiếu Ngạo
Xếp hạng Bang hội: ⚡5/46⚡
Level:
Chủ đề đã tạo: 🩸4141/4141🩸
Tiền mặt:
Ngân hàng:
Nhóm:
Danh hiệu: ⚝⚝⚝Truyền Thuyết⚝⚝⚝
Giới tính:
Ngày tham gia:
Đến từ:
Thiết bị:
Số điện thoại:
(Google Chrome 92.0.451)

Re: How to Change the Default Search URL Slug in WordPress - Thay đổi url tìm kiếm wordpress

#2 » Gửi bài gửi bởi JoseSv » 17/07/2021 00:52 » @522724

it is great WordPress uses SEO friendly URL structure for all pages on your website
JoseSv
Hình đại diện của thành viên
Rank: ☀️1/30☀️
Cấp độ:
Tu luyện:
Like:
Online:
Bang hội: ?????
Xếp hạng Bang hội: ⚡??/??⚡
Level:
Chủ đề đã tạo: 🩸???/4141🩸
Tiền mặt:
Nhóm:
Danh hiệu: ?????
Giới tính:
Ngày tham gia:
Đến từ:
Số điện thoại:
(Google Chrome 91.0.447)



Quay về C, C++, C#, Java, Python, PHP, JS, SQL ...

 


  • Chủ đề tương tự
    Trả lời
    Xem
    Bài viết mới nhất