Tối ưu seo url cho website hỏi đáp question2answer
Sau khi đã dựng xong một trang hỗ trợ khách hàng, trang hỏi đáp. Bạn cần tối ưu hóa một số thứ: giao diện gọn hơn, bố trí các chuyên mục hợp lý, chia sẻ trên các mạng xã hội về trang hỏi đáp của bạn. Rồi bước mà các webmaster quan tâm là SEO URL sao cho thân thiện nhất.Với các websitehỏi đáp là Tiếng Việt, Tiếng Trung, Tiếng Nhật, Tiếng Nga, Thái Lan...nếu dùng cách rewrite mặc định của q2a thì rất không thân thiện. Dưới đây là giải pháp cho bạn.
Rewrite friendly seo URL
File to edit :qa-include/qa-base.php
Find: function qa_q_request($questionid, $title)
Add the following code above that function:
function locdau($value)
{
//bat dau loc dau
$locdau_in = array (
'#(A|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ằ|Ẳ|Ẵ|Ặ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ)#',
'#(B)#',
'#(C)#',
'#(D|Đ|đ)#',
'#(E|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ)#',
'#(F)#',
'#(G)#',
'#(H)#',
'#(I|Í|Ì|Ỉ|Ĩ|Ị|í|ì|ỉ|ĩ|ị)#',
'#(J)#',
'#(K)#',
'#(L)#',
'#(M)#',
'#(N)#',
'#(O|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ)#',
'#(P)#',
'#(Q)#',
'#(R)#',
'#(S)#',
'#(T)#',
'#(U|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự)#',
'#(V)#',
'#(W)#',
'#(X)#',
'#(Ý|Ỳ|Ỷ|Ỹ|Ỵ|Y|ý|ỳ|ỷ|ỹ|ỵ|y)#',
'#(Z)#',
"/[^a-zA-Z0-9\-\_]/",
'#(@)#',
) ;
$locdau_out = array (
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'-',
'-',
) ;
$value = preg_replace($locdau_in, $locdau_out, $value);
$value = preg_replace('/(-)+/', '-', $value);
$value = str_replace(array('-quot', '"'), '', $value);
//ket thuc loc dau
return $value;
}
//End netdepviet SEO-URL
Continue to find:
$words=qa_string_to_words($title, true, false, false);
Add this above:
$tieude=locdau($title);
Then go to find:
return (int)$questionid.'/'.$title
Replace by:
return (int)$questionid.'/'.$tieude
Save and upload to the q2a site. No need to change the .htaccess file configuration .
* another way for other language:
$unitit = str_replace(array('а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'ъ', 'ы', 'э', 'ю', 'я'), array('a', 'b', 'v', 'g', 'd', 'e', 'jo', 'zh', 'z', 'i', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'ts', 'ch', 'sh', 'sch', 'j', 'j', 'y', 'e', 'y', 'ya'), $title);
//and make change something like this
return (int)$questionid.'/'.$unitit;
For Question2Answer 1.8.0 (Released 08.02.2018 )or later:
Find:
$title = qa_block_words_replace($title, qa_get_block_words_preg());
Add bellow it:
$tieude=locdau($title);
Find:
$slug = qa_slugify($title, qa_opt('q_urls_remove_accents'), qa_opt('q_urls_title_length'));
Replace by:
$slug = qa_slugify($tieude, qa_opt('q_urls_remove_accents'), qa_opt('q_urls_title_length'));
Save and upload the edited file.
Trang:
[1]