Murphy Tsai
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 前端工程師後端之旅 - 路由設計以及Slug SEO優化 路由的設計也是開發網站時的重點之一,不同的功能及頁面,甚至資料存取方式,都會收到Route規劃的影響。 我們得先知道,網站總共有哪些頁面,才能整理出頁面和頁面之間的關係,進而設計出合適的路由,下面是根據畫面整理出來的網站架構,如果對於網站畫面拆解有興趣的,可以參考上一篇: ### [從畫面拆解,到整理User Story](https://hackmd.io/h8GOsrcuTme4MibQfSnZuQ?both) 或可參考網站成果: http://mujingtsai.site/ ### 文章大綱: 1. 網站 Sitemap 2. 路由設計 3. Slug SEO 優化 ## 網站 Sitemap 根據該所有可到網站頁面可整理出如下面這樣的網站頁面圖, 這對確認需求有蠻大程度的幫助,討論需求時也比較不會東漏西漏: ### 前台Sitemap ![](https://i.imgur.com/y6r9iDi.png) ### 後台Sitemap ![](https://i.imgur.com/s3g9dZT.png) ## 路由設計: 原本的Route方式比較髒,雖然設計上算是Restful, 但route還要index.php還是不太美規,甚至有可能影響SEO, 因此我想要設計成直觀一點的路由。 ### 商品類別路由 ```rb /product/category/:category_id ``` ### 商品路由 ```rb /product/:product_id ``` ### 新聞類別&&新聞路由 仿照product,一樣的方式,把product改為news: ```rb /post/category/:category_id ``` ```rb /post/:post_id ``` ### 購物車路由 原來的購物車路由跟結帳路由被放在同一個層級下,容易令人疑惑,因此如果能夠拆開比較好: ``` /cart ``` ### 結帳頁面 ``` /checkout ``` ### 登入頁面 ``` /user/login ``` ### 會員資料頁: ``` /user/edit ``` ## Slug SEO 優化: Slug(別名) 是在URL裡面,藉由給每一個頁面一個不重複具有識別性的資料,達到以更語意化的方式存取資料,藉此提升SEO友善度。 很多時候在某個頁面有很多相同類型的資料要存取,比如商品列表內某一筆商品資料、某一筆文章資料......,我們會透過在路由內搭配變數,利用商品id去存取,例如: ``` /products/:id ``` 而在使用上我們就可以透過「/products/12」去找到第12筆商品內容頁面。基本上只要能夠確保每個:id變數是獨一無二具有識別性的,就能透過這個路由一次性處理多筆資料。 但是這樣子的用法對SEO來說並不夠友善,要針對路由優化SEO,有一個大原則是讓URL**簡短、清楚、語意化**,其實在這個情況下,可以與路由搭配的識別性資料,也不一定只有id。 我們可以一筆一筆商品自己給定不重複的slug, 但不難想到,以商品來說,通常**商品名稱**也是不會重複的識別性資料。 所以我們可以直接用拿來搭配使用,而且這樣子一看就知道是對應到哪個頁面了。 例如: ``` products/categories/限時優惠 ``` 當然我們還是得做一些防止slug重複的方法,以免意外性的名稱重複導致網站無法運作,由於使用Slug通常是在資料庫商品資料表的欄位內多插入一個Slug欄位,所以必須指定資料欄位為unique,防止相同的資料被寫入第二次,以rails 來說就是在migration寫入類似: ``` rb add_column :posts , :slug , :string , :index => { :unique => true } ``` 以指定唯一的索引,你可以透過 http://mujingtsai.site/products/categories/新品上架 來看到我的實作成果。

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully