Difference between revisions of "Search Engine Friendly URLs/zh-tw"

From Joomla! Documentation

(Created page with "搜尋引擎網址友善化")
 
(Created page with "=== 系統 - SEF 外掛 === Joomla 的 ''系統 - SEF'' 外掛繼承 <code>JPlugin</code> 並且會實行<code>onAfterRender()</code> 功能。在此功能中,回應的內...")
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude><languages /></noinclude>
 
<noinclude><languages /></noinclude>
 
<onlyinclude>
 
<onlyinclude>
'''Search engine friendly (SEF)''', '''human-readable''' or [[wikipedia:Clean_URL|clean URLs]] are URLs that make sense to both humans and search engines because they explain the path to the particular page they point to. Since version 1.5, Joomla! is capable of creating and parsing URLs in any format, including SEF URLs. This does not depend on URL rewriting executed by the web server, so it works even if Joomla! runs a server other than Apache with the mod_rewrite module. The SEF URLs follow a certain fixed pattern, but the user can define a [[Alias|short descriptive text (alias)]] for each segment of the URL.
+
'''搜尋引擎網址友善化 (SEF)''', '''人類可讀''' 或稱為 [[wikipedia:Clean_URL|乾淨 URL]] 是指 URL 能解釋特定頁面的內容,對於人類或是搜尋引擎而言是有意義的。從{{JVer|1.5}}起,Joomla! 就可以建立並解析任何格式的 URLs ,也包含 SEF URL。這並不需要依賴網站伺服器的 URL rewriting 是啟用的,因此即使 Joomla! 執行於 Apache + mod_rewrite 模組以外的網站伺服器都能用。SEF URL 會依據特定的固定格式,然而用戶可以為每一個部分來定義 [[Alias|short descriptive text (別名)]]
  
Internally, the local part of a SEF URL (the part after the domain name) is called a '''route'''. Creating and processing SEF URLs is therefore referred to as '''routing''', and the relevant code is called a '''router'''.
+
在內部,SEF URL 的本機部分 (在域名之後的部份)稱為'''路由'''。因此建立以及執行 SEF URL也是名為 '''路由''',相關的程式碼也稱為'''路由'''
 
</onlyinclude>
 
</onlyinclude>
A good example of routing is the URL to "Welcome to Joomla!" article in the sample data.
+
範例資料庫中的文章"Welcome to Joomla!" URL 是一個不錯的路由範例。
  
* Without SEF URLs turned on, the URL is <code><nowiki>http://www.example.com/index.php?option=com_content&view=article&id=1:welcome-to-joomla&catid=1:latest-news&Itemid=50</nowiki></code>
+
* SEF URL 沒有打開時, URL 是 <code><nowiki>http://www.example.com/index.php?option=com_content&view=article&id=1:welcome-to-joomla&catid=1:latest-news&Itemid=50</nowiki></code>
* With SEF URLs on and mod_rewrite off, it's <code><nowiki>http://www.example.com/index.php/the-­news/1-­latest­-news/1­-welcome­-to­-joomla</nowiki></code>
+
* SEF URL 打開但是 mod_rewrite 關閉時,URL 是 <code><nowiki>http://www.example.com/index.php/the-­news/1-­latest­-news/1­-welcome­-to­-joomla</nowiki></code>
* With both SEF URLs and mod_rewrite on, it's <code><nowiki>http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla</nowiki></code>
+
* SEF URL 和 mod_rewrite 都打開時,URL 是 <code><nowiki>http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla</nowiki></code>
  
Search engine friendly URLs can be activated by turning on the '''Search Engine Friendly URLs''' option in the ''Global Configuration''. This option is on by default since Joomla! 1.6. See [[Enabling Search Engine Friendly (SEF) URLs]] for more information.
+
開啟''全站設定''中的'''搜尋引擎網址友善化''' 選項,即可啟用搜尋引擎網址友善化。自{{JVer|1.6}}起這個選項預設是啟用的。更多資訊請參見 [[Enabling Search Engine Friendly (SEF) URLs]]
  
== FAQs ==
+
== 常見問題 ==
  
=== What do the numbers in the URL mean? ===
+
=== URL 當中的數目字是什麼東東? ===
By comparing the old and the new URL we can see numbers in the old URL,
+
比較啟用前後的 URL ,我們可以在原本的 URL 看到數字
  
 
<pre><nowiki>http://www.example.com/index.php?option=com_content&view=article&id=1:welcome-to-joomla&catid=1:latest-news&Itemid=50</nowiki></pre>
 
<pre><nowiki>http://www.example.com/index.php?option=com_content&view=article&id=1:welcome-to-joomla&catid=1:latest-news&Itemid=50</nowiki></pre>
  
but also in the new URL:
+
在新的 URL 當中也有:
  
 
<pre><nowiki>http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla</nowiki></pre>
 
<pre><nowiki>http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla</nowiki></pre>
  
These numbers are the parameters that are needed by Joomla! to get the internal URL and show the page you want to see. (In this case, the first numeral one is the ID of the category, the second numeral one is the ID of the article.)
+
這個數字是 Joomla! 需要的參數,以取得 internal URL 並顯示您需要看到的頁面。 (在這個案例中,前面的數字<tt>1</tt>是目錄的ID,第二個數字<tt>1</tt>是文章的ID。)
  
=== There is no <code>index.php</code> in the URL anymore. Can I delete the file now? ===
+
=== 在網址列中已經看不到 <code>index.php</code> 了,所以我我可以把檔案刪除掉嗎? ===
No! The URL doesn't contain the <code>index.php</code> anymore, but internally the mod_rewrite will only redirect to the original path without showing it to you.
+
不可以!雖然網址列看不到 <code>index.php</code>,但是 mod_rewrite, but internally the mod_rewrite will only redirect to the original path without showing it to you.
  
=== What is the [[Alias]] value? And how does it get created? ===
+
=== 什麼是 [[S:MyLanguage/Alias|別名]] 值?它如何被建立? ===
 
Alias is listed beneath the Title field in Articles, Categories, Sections and Menu Items. Joomla! can automatically create the alias for you. An automatic alias begins with the title. All upper case letters are changed to lower case. Spaces and special characters not allowed in a URL; they are changed to dashes.
 
Alias is listed beneath the Title field in Articles, Categories, Sections and Menu Items. Joomla! can automatically create the alias for you. An automatic alias begins with the title. All upper case letters are changed to lower case. Spaces and special characters not allowed in a URL; they are changed to dashes.
  
=== I want to specify my own value for Alias. ===
+
=== 我想要自行指定別名的值 ===
If you do not like the alias provided by Joomla!, you can enter a value of your choosing into that field. Many believe using good keywords in your URL helps search engine optimization. You can do so by including those keywords in your title, and allowing Joomla! to create the alias, or by creating the alias yourself.
+
如果您不喜歡 Joomla! 提供的別名,您可以使用, you can enter a value of your choosing into that field. 好些人相信,在URL中妥善使用關鍵字會改善搜尋引擎排名。You can do so by including those keywords in your title, and allowing Joomla! to create the alias, or by creating the alias yourself.
  
=== How is Alias used in a URL? ===
+
=== 別名是如何使用於 URL當中? ===
For a menu item, Joomla! uses the alias as the URL slug. Assume that you use the first two SEF URL options and you create a menu item called Products. Your URL would be example.com/products.
+
以選單項目來說,Joomla! 會使用別名來當做網址後綴(URL slug)。假設您使用了頭兩個 SEF URL 項目,然後您建立一個名為 Products 的選單項目,那麼您的 URL 將會是 <tt>example.com/products</tt>
  
 
Joomla! also uses the primary key values of data within the URL to help the router navigate to the correct page. Continuing with the previous example, if your products menu item was for an Article­/Category Blog, the link for the Article Title and/or Read More link would have three parts:
 
Joomla! also uses the primary key values of data within the URL to help the router navigate to the correct page. Continuing with the previous example, if your products menu item was for an Article­/Category Blog, the link for the Article Title and/or Read More link would have three parts:
Line 55: Line 55:
 
''This section describes Joomla!'s core (built-in) routing mechanism. Routing extensions may change the way routes are created on your system.''
 
''This section describes Joomla!'s core (built-in) routing mechanism. Routing extensions may change the way routes are created on your system.''
  
=== Route Formats ===
+
=== 路由格式 ===
  
 
To describe the Joomla! routing mechanism in more detail, we first need to pin down what we refer to as a '''route'''. Suppose that Joomla! has been installed in <code><nowiki>http://example.com/sites/first/</nowiki></code>. The installation path is generally referred to as the '''base URL'''. A possible example URL is <code><nowiki>http://example.com/sites/first/products/32-fruit/1-apple</nowiki></code>. The first part of this URL is the aforementioned base URL, and neither Joomla! nor any component router can create URLs with a different first part. The second part, <code>products/32-fruit/1-apple</code>, is a '''route''', consisting of three '''segment'''s.
 
To describe the Joomla! routing mechanism in more detail, we first need to pin down what we refer to as a '''route'''. Suppose that Joomla! has been installed in <code><nowiki>http://example.com/sites/first/</nowiki></code>. The installation path is generally referred to as the '''base URL'''. A possible example URL is <code><nowiki>http://example.com/sites/first/products/32-fruit/1-apple</nowiki></code>. The first part of this URL is the aforementioned base URL, and neither Joomla! nor any component router can create URLs with a different first part. The second part, <code>products/32-fruit/1-apple</code>, is a '''route''', consisting of three '''segment'''s.
Line 63: Line 63:
 
It is also possible (for extensions) to ask the system to create a route without supplying a menu item to route through. In that case, the system will usually decide to create a special route that has the word <code>component</code> as the first segment. These routes are created using a fixed format: the name of the component (without the leading <code>com_</code>) is selected as the second segment and any parameters as the other segments.
 
It is also possible (for extensions) to ask the system to create a route without supplying a menu item to route through. In that case, the system will usually decide to create a special route that has the word <code>component</code> as the first segment. These routes are created using a fixed format: the name of the component (without the leading <code>com_</code>) is selected as the second segment and any parameters as the other segments.
  
=== Limitations ===
+
=== 限制 ===
  
 
It is important to note creating a menu item is the ''only'' way for a Joomla! user to define a route that leads to a specific component. It is, however, possible to create a route without showing it on the site (in a menu). An often-applied method is to create a menu item in a menu that isn't displayed anywhere. Such a menu is usually called a [[Menu|hidden menu]].
 
It is important to note creating a menu item is the ''only'' way for a Joomla! user to define a route that leads to a specific component. It is, however, possible to create a route without showing it on the site (in a menu). An often-applied method is to create a menu item in a menu that isn't displayed anywhere. Such a menu is usually called a [[Menu|hidden menu]].
Line 78: Line 78:
 
Joomla routes are created and resolved by [[JRouter|the JRouter class]]. This class looks in the component root of the currently active component (specified in the <code>option</code> parameter in the query string) and includes the <code>router.php</code> file in that component's root directory. It then calls one of two functions: one for creating the SEF URL and one for interpreting the SEF URL.
 
Joomla routes are created and resolved by [[JRouter|the JRouter class]]. This class looks in the component root of the currently active component (specified in the <code>option</code> parameter in the query string) and includes the <code>router.php</code> file in that component's root directory. It then calls one of two functions: one for creating the SEF URL and one for interpreting the SEF URL.
  
The JRouter class is overridden by the Joomla CMS in <code>/includes/router.php</code>. In this file the build and parse functions are overridden to properly build and parse the URLs for the Joomla CMS.
+
<code>/includes/router.php</code>中 Joomla CMS 會覆寫 JRouter class。在這個檔案中,建立及解析的功能會被覆蓋,並且為 Joomla CMS 解析 URL。
  
 
The <code>router.php</code> file in each component (for example, <code>/components/com_content/router.php</code>) should contain the following two functions:
 
The <code>router.php</code> file in each component (for example, <code>/components/com_content/router.php</code>) should contain the following two functions:
Line 90: Line 90:
 
** Returns: a name => value array of the querystring variables that the link maps to
 
** Returns: a name => value array of the querystring variables that the link maps to
  
=== The SEF Plugin ===
+
=== 系統 - SEF 外掛 ===
The Joomla ''System - SEF'' plugin inherits <code>JPlugin</code> and implements the <code>onAfterRender()</code> function. In this function the body of the response that will be sent to the browser is retrieved using <code>JResponse::getBody()</code>. The body of the response is then searched for links containing <code>/index.php...</code> and replaces them with a correct SEF URL by calling <code>JRoute::_(''url'')</code>.
+
Joomla ''系統 - SEF'' 外掛繼承 <code>JPlugin</code> 並且會實行<code>onAfterRender()</code> 功能。在此功能中,回應的內容會使用 <code>JResponse::getBody()</code>來取回並送給瀏覽器。接著回應的內容會搜尋包含有 <code>/index.php...</code> 的連結,並且透過呼叫<code>JRoute::_(''url'')</code>來取代為正確的 SEF URL。
  
 
JRoute builds SEF URLs by instantiating a <code>JRouter</code> object and requesting that it build the correct link from the passed in URL.
 
JRoute builds SEF URLs by instantiating a <code>JRouter</code> object and requesting that it build the correct link from the passed in URL.
  
=== Handling SEF URLs ===
+
=== 處理 SEF URL ===
By default the SEF URLs are handled by the <code>JRouterSite</code> object (from <code>/includes/router.php</code>) and is called by a call to <code>JApplication::route()</code> in index.php. This call is made on the <code>$app</code> variable which is actually an instance of <code>JSite</code> (from <code>/includes/application.php</code>).
+
預設中會由 <code>JRouterSite</code> 物件 (<code>/includes/router.php</code>) 處理 SEF URL, and is called by a call to <code>JApplication::route()</code> in index.php. This call is made on the <code>$app</code> variable which is actually an instance of <code>JSite</code> (from <code>/includes/application.php</code>).
  
<code>JApplication::route()</code> has a non-destructive result on the <code>$_GET</code> array. That is, <code>JApplication::route()</code> sets variables in <code>$_GET</code> by calling <code>JRequest::set()</code> with the overwrite flag set to false. Thus if a variable name is returned from <code>JRouter::route()</code> that is already in <code>$_GET</code>, it will not put that value into <code>$_GET</code>. This allows for custom routing.
+
<code>JApplication::route()</code> has a non-destructive result on the <code>$_GET</code> array. That is, <code>JApplication::route()</code> sets variables in <code>$_GET</code> by calling <code>JRequest::set()</code> with the overwrite flag set to false. Thus if a variable name is returned from <code>JRouter::route()</code> that is already in <code>$_GET</code>, it will not put that value into <code>$_GET</code>. 這可以實現客製化路由。
  
=== Custom Routing ===
+
=== 客製化路由 ===
 
Joomla allows you to create your own routing mechanism. In order to create this mechanism you must have a plugin that overrides the <code>JPlugin::onAfterInitialise()</code> function. This function then parses the URL and creates the needed variables in <code>$_GET</code> before the standard Joomla routing is done.
 
Joomla allows you to create your own routing mechanism. In order to create this mechanism you must have a plugin that overrides the <code>JPlugin::onAfterInitialise()</code> function. This function then parses the URL and creates the needed variables in <code>$_GET</code> before the standard Joomla routing is done.
  
''See [[Creating a System Plugin to augment JRouter]] for an example.''
+
''請見 [[Creating a System Plugin to augment JRouter]] ,當中有範例。''
  
[[Category:Search Engine Friendly URLs| ]]
+
[[Category:Search Engine Friendly URLs{{#translation:}}]]

Latest revision as of 05:07, 18 February 2021

Other languages:
Bahasa Indonesia • ‎Deutsch • ‎English • ‎Kiswahili • ‎Nederlands • ‎català • ‎español • ‎français • ‎português • ‎português do Brasil • ‎فارسی • ‎中文(台灣)‎ • ‎日本語

搜尋引擎網址友善化 (SEF), 人類可讀 或稱為 乾淨 URL 是指 URL 能解釋特定頁面的內容,對於人類或是搜尋引擎而言是有意義的。從Joomla 1.5起,Joomla! 就可以建立並解析任何格式的 URLs ,也包含 SEF URL。這並不需要依賴網站伺服器的 URL rewriting 是啟用的,因此即使 Joomla! 執行於 Apache + mod_rewrite 模組以外的網站伺服器都能用。SEF URL 會依據特定的固定格式,然而用戶可以為每一個部分來定義 short descriptive text (別名)

在內部,SEF URL 的本機部分 (在域名之後的部份)稱為路由。因此建立以及執行 SEF URL也是名為 路由,相關的程式碼也稱為路由

範例資料庫中的文章"Welcome to Joomla!" URL 是一個不錯的路由範例。

  • 在 SEF URL 沒有打開時, URL 是 http://www.example.com/index.php?option=com_content&view=article&id=1:welcome-to-joomla&catid=1:latest-news&Itemid=50
  • 在 SEF URL 打開但是 mod_rewrite 關閉時,URL 是 http://www.example.com/index.php/the-­news/1-­latest­-news/1­-welcome­-to­-joomla
  • 在 SEF URL 和 mod_rewrite 都打開時,URL 是 http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla

開啟全站設定中的搜尋引擎網址友善化 選項,即可啟用搜尋引擎網址友善化。自Joomla 1.6起這個選項預設是啟用的。更多資訊請參見 Enabling Search Engine Friendly (SEF) URLs

常見問題

URL 當中的數目字是什麼東東?

比較啟用前後的 URL ,我們可以在原本的 URL 看到數字

http://www.example.com/index.php?option=com_content&view=article&id=1:welcome-to-joomla&catid=1:latest-news&Itemid=50

在新的 URL 當中也有:

http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla

這個數字是 Joomla! 需要的參數,以取得 internal URL 並顯示您需要看到的頁面。 (在這個案例中,前面的數字1是目錄的ID,第二個數字1是文章的ID。)

在網址列中已經看不到 index.php 了,所以我我可以把檔案刪除掉嗎?

不可以!雖然網址列看不到 index.php,但是 mod_rewrite, but internally the mod_rewrite will only redirect to the original path without showing it to you.

什麼是 別名 值?它如何被建立?

Alias is listed beneath the Title field in Articles, Categories, Sections and Menu Items. Joomla! can automatically create the alias for you. An automatic alias begins with the title. All upper case letters are changed to lower case. Spaces and special characters not allowed in a URL; they are changed to dashes.

我想要自行指定別名的值

如果您不喜歡 Joomla! 提供的別名,您可以使用, you can enter a value of your choosing into that field. 好些人相信,在URL中妥善使用關鍵字會改善搜尋引擎排名。You can do so by including those keywords in your title, and allowing Joomla! to create the alias, or by creating the alias yourself.

別名是如何使用於 URL當中?

以選單項目來說,Joomla! 會使用別名來當做網址後綴(URL slug)。假設您使用了頭兩個 SEF URL 項目,然後您建立一個名為 Products 的選單項目,那麼您的 URL 將會是 example.com/products

Joomla! also uses the primary key values of data within the URL to help the router navigate to the correct page. Continuing with the previous example, if your products menu item was for an Article­/Category Blog, the link for the Article Title and/or Read More link would have three parts:

  • The menu item URL - example.com/products;
  • Plus, the primary key for the Category and the Category alias - 32-fruit;
  • Plus, the primary key for the Article and the Article alias - 1-apple;

The complete URL is: http://example.com/products/32-fruit/1-apple

How can I get rid of the numbers in the SEF URLs?

The numbers in the SEF URL are needed by Joomla!'s router to know how to direct site traffic. Once the router logic stabilizes, simple third party system plugins can be developed to augment the router capabilities by allowing more choice. At that time, numbers will likely be removed from the URL.

Route Formats and the Routing Mechanism

This section describes Joomla!'s core (built-in) routing mechanism. Routing extensions may change the way routes are created on your system.

路由格式

To describe the Joomla! routing mechanism in more detail, we first need to pin down what we refer to as a route. Suppose that Joomla! has been installed in http://example.com/sites/first/. The installation path is generally referred to as the base URL. A possible example URL is http://example.com/sites/first/products/32-fruit/1-apple. The first part of this URL is the aforementioned base URL, and neither Joomla! nor any component router can create URLs with a different first part. The second part, products/32-fruit/1-apple, is a route, consisting of three segments.

The first segment of a route is, for regular URLs, the alias of a menu item. The SEF URL is said to be routed through that menu item. The other segments are determined entirely by the router of the component that provides the type of the menu item. The Category - Blog menu item type, for example, is provided by the Content component, and therefore that component's router is responsible for building and parsing the remaining segments.

It is also possible (for extensions) to ask the system to create a route without supplying a menu item to route through. In that case, the system will usually decide to create a special route that has the word component as the first segment. These routes are created using a fixed format: the name of the component (without the leading com_) is selected as the second segment and any parameters as the other segments.

限制

It is important to note creating a menu item is the only way for a Joomla! user to define a route that leads to a specific component. It is, however, possible to create a route without showing it on the site (in a menu). An often-applied method is to create a menu item in a menu that isn't displayed anywhere. Such a menu is usually called a hidden menu.

The previous paragraph implies that it is not possible to make one component responsible for handling all routes. For example, it is not possible to specify that the URL http://example.com/thealias should display the Content item with the alias thealias, where thealias could be any word. If this needs to be done for a small number of articles, menu items can be created manually for these. Else a routing extension is necessary.

This routing mechanism is therefore not as flexible as users sometimes require. On the other hand, it has one large advantage: it reduces the chance of ambiguous routes (routes that could lead to two different pages). Since the first segment of a route is always a menu item alias, the system immediately knows which component's router must be used to parse it.

Implementation Details

Handling Routes

This section describes the routing implementation. If you are a component developer, see Supporting SEF URLs in your component.

Joomla routes are created and resolved by the JRouter class. This class looks in the component root of the currently active component (specified in the option parameter in the query string) and includes the router.php file in that component's root directory. It then calls one of two functions: one for creating the SEF URL and one for interpreting the SEF URL.

/includes/router.php中 Joomla CMS 會覆寫 JRouter class。在這個檔案中,建立及解析的功能會被覆蓋,並且為 Joomla CMS 解析 URL。

The router.php file in each component (for example, /components/com_content/router.php) should contain the following two functions:

  • ContentBuildRoute - this builds the SEF URL
    • Parameters
      • $query - this is a named array containing the querystring variables
    • Returns: an array of segments where each segment is separated by a '/' when later combined to create the actual URL (the items in the array should not contain '/' characters)
  • ContentParseRoute - this interprets an SEF URL
    • Parameters
      • $segments - this is an array that contains the segments of the URL requested.
    • Returns: a name => value array of the querystring variables that the link maps to

系統 - SEF 外掛

Joomla 的 系統 - SEF 外掛繼承 JPlugin 並且會實行onAfterRender() 功能。在此功能中,回應的內容會使用 JResponse::getBody()來取回並送給瀏覽器。接著回應的內容會搜尋包含有 /index.php... 的連結,並且透過呼叫JRoute::_(url)來取代為正確的 SEF URL。

JRoute builds SEF URLs by instantiating a JRouter object and requesting that it build the correct link from the passed in URL.

處理 SEF URL

預設中會由 JRouterSite 物件 (從 /includes/router.php) 處理 SEF URL, and is called by a call to JApplication::route() in index.php. This call is made on the $app variable which is actually an instance of JSite (from /includes/application.php).

JApplication::route() has a non-destructive result on the $_GET array. That is, JApplication::route() sets variables in $_GET by calling JRequest::set() with the overwrite flag set to false. Thus if a variable name is returned from JRouter::route() that is already in $_GET, it will not put that value into $_GET. 這可以實現客製化路由。

客製化路由

Joomla allows you to create your own routing mechanism. In order to create this mechanism you must have a plugin that overrides the JPlugin::onAfterInitialise() function. This function then parses the URL and creates the needed variables in $_GET before the standard Joomla routing is done.

請見 Creating a System Plugin to augment JRouter ,當中有範例。