在 URL 地址中使用項目名稱而不是 ID (Using item's name in the URL address instead of IDs)


問題描述

在 URL 地址中使用項目名稱而不是 ID (Using item's name in the URL address instead of IDs)

I have built a PHP‑MYSQL website that retrieves products from a database. The items are taken by id in the URL like this: index.php?id=25.

However, I just read that this is not the best option for SEO purposes.

Is there any simple way to have the item name and category populated in the URL instead of the id number? Or should I call each item using the field NAME and CATEGORY from the database?

Thanks!

‑‑‑‑‑

參考解法

方法 1:

When you print the link add some detail to it (that your index.php will not use anyway).  

So your links will look like: index.php?id=25&c=Airplanes&q=Fighter+Jet+Z672  

index.php will function as before via id and ignore &c= and &q=.  

To make this even better you'll use a .htaccess file to rewrite your links to something like: mysite.com/Airplanes/25‑Fighter‑Jet‑Z672

(by samyb8CSᵠ)

參考文件

  1. Using item's name in the URL address instead of IDs (CC BY‑SA 3.0/4.0)

#url #MySQL #PHP






相關問題

正則表達式查找和替換 url 不起作用或如何使其起作用 (Regex to Find and Replace url does not work or how to make it work)

子網站的 URL 重寫? (URL Rewriting for a Subsite?)

使用 htaccess 從基本 URL 中刪除變量 (Remove variable from base URL with htaccess)

在 URL 地址中使用項目名稱而不是 ID (Using item's name in the URL address instead of IDs)

Perl Chèn chuỗi vào url tại các địa điểm cụ thể (Perl Inserting string into a url at specific places)

Cách ẩn mọi thứ sau tên trang web của bạn bằng .htaccess (How to hide everything after your webpage name with .htaccess)

在 gwt 框架中使用參數更改 url (Changing url with parameters in gwt framework)

用於 SEO 目的的 Nodejs URL 修改 (Nodejs URL modifications for SEO purposes)

將用戶重定向到外部站點 (Redirecting user to external site)

Python 循環遍歷 csv 文件中的 url 返回 \ufeffhttps:// (Python Looping through urls in csv file returns \ufeffhttps://)

主頁中的 React Router 目標 div id (React Router target div id in home page)

.htaccess https、www 和子域靜默重寫 (.htaccess https, www and subdomain silent rewrite)







留言討論