Enabling Search Engine Friendly (SEF) URLs on Nginx: Difference between revisions
From Joomla! Documentation
No edit summary |
Some markup changes. |
||
| Line 1: | Line 1: | ||
<noinclude><languages /></noinclude> | <noinclude><languages /></noinclude> | ||
{{:Search Engine Friendly URLs/<translate>en</translate>}} | {{:Search Engine Friendly URLs/<translate>en</translate>}} | ||
<translate><!--T:14--> This article addresses SEF URLs under the popular, open-source [http://nginx. | <translate><!--T:14--> | ||
This article addresses SEF URLs under the popular, open-source [http://nginx.org/ Nginx webserver].</translate> | |||
<translate><!--T:15--> | |||
{{JVer|2.5}} Since Joomla! 2.5, basic SEF URLs are enabled by default. {{JVer|1.5}} In prior versions you need to use the Global Configuration to enable them. The instructions below still apply if you want to use Apache's ''mod_rewrite/URL'' rewriting.</translate> | |||
<onlyinclude> | <onlyinclude> | ||
<translate><!--T:1--> | <translate><!--T:1--> | ||
*Please add | *Please add this code to your server (vhost) configuration in the ''nginx.conf'' file:</translate> | ||
<pre> | <pre> | ||
# <translate>Support Clean (aka Search Engine Friendly) URLs</translate> | # <translate>Support Clean (aka Search Engine Friendly) URLs</translate> | ||
| Line 16: | Line 17: | ||
<translate><!--T:2--> | <translate><!--T:2--> | ||
* If the above does not work, add | * If the above does not work, add this code to your server configuration in the ''nginx.conf'' file: (This worked with ''nginx 1.4.6'' on Ubuntu.)</translate> | ||
<pre> | <pre> | ||
server { | server { | ||
| Line 23: | Line 24: | ||
expires 1d; | expires 1d; | ||
# | # Enable joomla SEF URL's inside Nginx | ||
try_files $uri $uri/ /index.php?$args; | try_files $uri $uri/ /index.php?$args; | ||
} | } | ||
| Line 31: | Line 32: | ||
<translate><!--T:3--> | <translate><!--T:3--> | ||
* Log on to your | * Log on to your Backend and open the Global Configuration.</translate> | ||
<translate><!--T:4--> | <translate><!--T:4--> | ||
* Enable the | * Enable the ''Search Engine Friendly URLs'' option and ''Save''. This option converts the URLs from the native Joomla! format to the SEF format.</translate> | ||
<translate><!--T:5--> | <translate><!--T:5--> | ||
*: Verify that your site works correctly. Your URLs should now look like | *: Verify that your site works correctly. Your URLs should now look like ''<nowiki>https://www.example.com/index.php/the-news/1-latest-news/1-welcome-to-joomla</nowiki>''.</translate> | ||
<translate><!--T:6--> | <translate><!--T:6--> | ||
*: If your site does not work correctly, please see [[Why does your site get messed up when you turn on SEF (Search Engine Friendly URLs)?]]</translate> | *: If your site does not work correctly, please see [[Why does your site get messed up when you turn on SEF (Search Engine Friendly URLs)?]]</translate> | ||
<translate><!--T:7--> | <translate><!--T:7--> | ||
* Enable the | * Enable the ''Use Apache mod_rewrite/URL rewriting'' option and ''Save''. This option uses the Apache ''mod_rewrite'' function to eliminate the ''index.php'' portion of the URL</translate> | ||
<translate><!--T:8--> | <translate><!--T:8--> | ||
*: Verify that your site works correctly. Your URLs should now look like | *: Verify that your site works correctly. Your URLs should now look like ''<nowiki>https://www.example.com/the-news/1-latest-news/1-welcome-to-joomla</nowiki>''.</translate> | ||
<translate><!--T:9--> | <translate><!--T:9--> | ||
*: If this option causes errors, please see [[Common problems when enabling Search Engine Friendly (SEF) URLs]].</translate> | *: If this option causes errors, please see [[Common problems when enabling Search Engine Friendly (SEF) URLs]].</translate> | ||
<translate><!--T:10--> | <translate><!--T:10--> | ||
*:: If it is not enabled and you have access to the file | *:: If it is not enabled and you have access to the file ''apache/conf/httpd.conf'', open that file and verify that the line ''LoadModule rewrite_module modules/mod_rewrite.so'' is uncommented. If necessary, uncomment the line and restart the Apache web server.</translate> | ||
<translate><!--T:11--> | <translate><!--T:11--> | ||
*:: If ''mod_rewrite'' cannot be enabled, leave this option off. It does not matter if you leave the | *:: If ''mod_rewrite'' cannot be enabled, leave this option off. It does not matter if you leave the ''.htaccess'' file renamed.</translate> | ||
<translate><!--T:12--> | <translate><!--T:12--> | ||
* | * If you think this is necessary, enable ''Add suffix to URLs'' and ''Save''. This option adds ''.html'' to the end of URLs. There are different opinions on whether this is necessary or even useful. Search engines do not seem to care if your URLs end in ''.html'' or not.</translate> | ||
<translate><!--T:13--> | <translate><!--T:13--> | ||
* Open the Plugin Manager and enable the | * Open the Plugin Manager and enable the ''System - SEF plugin''. This plugin adds SEF support to links in your Joomla articles. It operates directly on the HTML and does not require a special tag.</translate> | ||
</onlyinclude> | </onlyinclude> | ||
Latest revision as of 20:18, 7 November 2022
Search engine friendly (SEF), human-readable or 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 on a server other than Apache with the mod_rewrite module. The SEF URLs follow a certain fixed pattern, but the user can define a short descriptive text (alias) for each segment of the URL.
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.
This article addresses SEF URLs under the popular, open-source Nginx webserver.
Since Joomla! 2.5, basic SEF URLs are enabled by default.
In prior versions you need to use the Global Configuration to enable them. The instructions below still apply if you want to use Apache's mod_rewrite/URL rewriting.
- Please add this code to your server (vhost) configuration in the nginx.conf file:
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
- If the above does not work, add this code to your server configuration in the nginx.conf file: (This worked with nginx 1.4.6 on Ubuntu.)
server {
....
location / {
expires 1d;
# Enable joomla SEF URL's inside Nginx
try_files $uri $uri/ /index.php?$args;
}
....
}
- Log on to your Backend and open the Global Configuration.
- Enable the Search Engine Friendly URLs option and Save. This option converts the URLs from the native Joomla! format to the SEF format.
- Verify that your site works correctly. Your URLs should now look like https://www.example.com/index.php/the-news/1-latest-news/1-welcome-to-joomla.
- If your site does not work correctly, please see Why does your site get messed up when you turn on SEF (Search Engine Friendly URLs)?
- Enable the Use Apache mod_rewrite/URL rewriting option and Save. This option uses the Apache mod_rewrite function to eliminate the index.php portion of the URL
- Verify that your site works correctly. Your URLs should now look like https://www.example.com/the-news/1-latest-news/1-welcome-to-joomla.
- If this option causes errors, please see Common problems when enabling Search Engine Friendly (SEF) URLs.
- If it is not enabled and you have access to the file apache/conf/httpd.conf, open that file and verify that the line LoadModule rewrite_module modules/mod_rewrite.so is uncommented. If necessary, uncomment the line and restart the Apache web server.
- If mod_rewrite cannot be enabled, leave this option off. It does not matter if you leave the .htaccess file renamed.
- If you think this is necessary, enable Add suffix to URLs and Save. This option adds .html to the end of URLs. There are different opinions on whether this is necessary or even useful. Search engines do not seem to care if your URLs end in .html or not.
- Open the Plugin Manager and enable the System - SEF plugin. This plugin adds SEF support to links in your Joomla articles. It operates directly on the HTML and does not require a special tag.