Difference between revisions of "Enabling Search Engine Friendly (SEF) URLs on Apache"

From Joomla! Documentation

m (fixing up)
(29 intermediate revisions by 9 users not shown)
Line 1: Line 1:
This article addresses SEF URLs under the popular, open-source Apache webserver.
+
{{version|2.5,3.x}}
 +
{{:Search Engine Friendly URLs/en}}
 +
This article addresses SEF URLs under the popular, open-source Apache webserver. SEF URL implementation is possible under Microsoft's IIS webserver as well, please see [[Enabling Search Engine Friendly (SEF) URLs on IIS]].
  
SEF URL implementation is possible under Microsoft's IIS webserver as well, please see [[IIS and Joomla]].
+
Since Joomla! {{JVer|1.6}}, 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.
 +
<onlyinclude>
 +
==Verify .htaccess is Enabled==
 +
Check that your Apache config file allows .htaccess overrides. You must make sure overrides are enabled or the .htaccess file in your Joomla! root directory will be ignored or cause an error. In the <Directory> section of your virtual host configuration file or in the main (<code>httpd.conf</code>) configuration file you must have something similar to the example below enabling overrides:
 +
<pre>
 +
<Directory "/home/user/public_html">
 +
  AllowOverride All
 +
</Directory>
  
{{JVer|1.6}} In Joomla! 1.6 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.
+
<Directory "/path/to/htdocs">
 +
  AllowOverride All Options=[an option],[an option],...
 +
</Directory>
 +
</pre>
 +
There are other ways to test if <code>.htaccess</code> is enabled if you do not have access to your site's configuration files. Please refer to the [http://httpd.apache.org/docs/current/howto/htaccess.html .htaccess tutorial] found on [http://www.apache.org/ The Apache Software Foundation] website for additional information.  
  
==Apache Instructions==
+
==Step by Step==
# Rename htaccess.txt to .htaccess.
+
These are step-by-step instructions. Please follow them in the order they are presented here. If a step fails, '''do not''' continue until you have solved the problem.
#: If Joomla is installed in its own folder, uncomment "RewriteBase <nowiki>/</nowiki>" and enter the Joomla folder name after the backslash.
+
# Rename the file <code>"htaccess.txt"</code> in your Joomla!'s base folder to <code>".htaccess"</code>.
#: Example: <code>RewriteBase /joomla</code>
+
# ''This step may not be necessary.'' Open <code>.htaccess</code> in a text editor. Uncomment <code>RewriteBase /</code> (remove the first character, #). If Joomla is installed in its own folder, the enter the Joomla folder name after the backslash. e.g. <code>RewriteBase /yourjoomlafolder</code>.
# Make sure that Mod_rewrite is working. Check that the line shown below in the file "apache/conf/httpd.conf" is uncommented. If necessary, uncomment the line and re-start the Apache web server.
+
# Log on to your Back-end and open the Global Configuration.
#: <code>LoadModule rewrite_module modules/mod_rewrite.so</code>
+
# Enable the '''Search Engine Friendly URLs''' option and ''Save''. This option converts the URLs from the native Joomla! format to the SEF format.
# In Global configuration, set the three SEF options. The action of the three parameters is as follows:
+
#: Check if your site works correctly. Your URLs should now look like:{{-}}<pre>http://www.example.com/index.php/the-­news/1-­latest­-news/1­-welcome­-to­-joomla</pre>{{-}}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)?]]
#* '''Search Engine Friendly URLs.''' Converts the URLs from the native Joomla! format to the SEF format.
+
# 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.
#* '''Use Apache mod_rewrite. ''' Uses the Apache "mod_rewrite" function to eliminate the "index.php" portion of the URL. If you don't want to use mod_rewrite, set this to "No" and don't rename the htaccess.txt. The SEF URLs feature will still work. The only difference is that you will see "index.php" in the URL, for example, <code><nowiki>http://www.yoursite.org/index.php/faq.html</nowiki></code>.  
+
#: Check if your site works correctly. Your URLs should now look like:{{-}}<pre>http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla</pre>{{-}}If this option causes errors, please see [[How to check if mod rewrite is enabled on your server]].
#* '''Add suffix to URLs.''' Adds ".html" to the end of URLs.
+
#* If it is not enabled and you have access to the file <code>apache/conf/httpd.conf</code>, open that file and check if the line <code>LoadModule rewrite_module modules/mod_rewrite.so</code> 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 <code>.htaccess</code> file renamed.
 +
# ''If you think this necessary'', enable '''Add suffix to URLs''' and ''Save''. This option adds <code>.html</code> 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 <code>.html</code> 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.
 +
</onlyinclude>
  
COMMENT:
+
<noinclude>
 
+
[[Category:Search Engine Friendly URLs]]
I believe the following are the most common possibilities for how URLs look in Joomla 1.5 or 1.6. Someone who knows better please confirm if the below is true:
+
[[Category:Tutorials]]
 
+
</noinclude>
<b>non-SEF</b> (Joomla 1.5 default): <code><nowiki>http://www.yoursite.org/8-category/7-alias</nowiki></code><br>
 
This is typical of the easiest Non-SEF URLs to understand. None of them are findable by search engines because they don't have an ".html" suffix. See SEF Ugly for their other disadvantages. These are a result of Joomla generating dynamic webpages and the need ensure their URL's are unique. In Joomla 1.6 you are more likely to see SEF Ugly than non-SEF because of the new default Global Configuration settings.
 
 
<b>SEF Ugly</b> (Joomla 1.6 default): <code><nowiki>http://www.yoursite.org/8-category/7-alias.html</nowiki></code> <br>
 
These are findable by search engines but ugly to remember and harder for a visitor to paste in an email. Their length may break a pasted URL in an email so you lose visitors. Most websites link to other pages of the same site. Admin must paste those links into your site, the easiest way to do that with SEF Ugly links is to browse to the target page while editing the other. Even with the Global settings above, you may get this if your hosting service has not correctly installed the appropriate server change.
 
 
 
<b>SEF Pretty URL</b>: <code><nowiki>http://www.yoursite.org/alias.html</nowiki></code><br>
 
This is findable by search engines and easy to remember. It is easier for Admin to type into another page of site or for a visitor to type in an email. This requires Joomla 1.5 or 1.6 with the three SEF settings as above, plus the appropriate server change installed. Notice Admin is responsible for ensuring alias names are unique for each page of your site. Browsing to an ambiguous page alias is unpredictable.
 
 
 
You want SEF Pretty URLs as early as possible. They will bring visitors because they remember it or a friend sent them an email about it. Converting from non-SEF or SEF Ugly can be a lot of URL retyping in your site. Search engines rate the URL itself worthy as a search result. Changing the URL later will lose historical search value for that page unless you take more technical measures.
 
<p>
 
[[User:Tmccully|Tim McCully.  In Genesis God uses one word for the light of day, the best part of what we call &quot;day&quot; now. http&#58;//TheTruthLover.com]] 03:46, 12 February 2011 (UTC)
 
[[Category:FAQ]]
 
[[Category:Administration FAQ]]
 
[[Category:Getting Started FAQ]]
 
[[Category:Search Engine Optimization]]
 
[[Category:Version 1.5 FAQ]]
 
[[Category:Version 1.6 FAQ]]
 
[[Category:Category Management]]
 

Revision as of 22:57, 6 November 2014


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 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 Apache webserver. SEF URL implementation is possible under Microsoft's IIS webserver as well, please see Enabling Search Engine Friendly (SEF) URLs on IIS.

Since Joomla! Joomla 1.6, 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.

Verify .htaccess is Enabled[edit]

Check that your Apache config file allows .htaccess overrides. You must make sure overrides are enabled or the .htaccess file in your Joomla! root directory will be ignored or cause an error. In the <Directory> section of your virtual host configuration file or in the main (httpd.conf) configuration file you must have something similar to the example below enabling overrides:

<Directory "/home/user/public_html">
  AllowOverride All
</Directory>

<Directory "/path/to/htdocs">
  AllowOverride All Options=[an option],[an option],...
</Directory>

There are other ways to test if .htaccess is enabled if you do not have access to your site's configuration files. Please refer to the .htaccess tutorial found on The Apache Software Foundation website for additional information.

Step by Step[edit]

These are step-by-step instructions. Please follow them in the order they are presented here. If a step fails, do not continue until you have solved the problem.

  1. Rename the file "htaccess.txt" in your Joomla!'s base folder to ".htaccess".
  2. This step may not be necessary. Open .htaccess in a text editor. Uncomment RewriteBase / (remove the first character, #). If Joomla is installed in its own folder, the enter the Joomla folder name after the backslash. e.g. RewriteBase /yourjoomlafolder.
  3. Log on to your Back-end and open the Global Configuration.
  4. Enable the Search Engine Friendly URLs option and Save. This option converts the URLs from the native Joomla! format to the SEF format.
    Check if your site works correctly. Your URLs should now look like:
    http://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)?
  5. 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.
    Check if your site works correctly. Your URLs should now look like:
    http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla
    If this option causes errors, please see How to check if mod rewrite is enabled on your server.
    • If it is not enabled and you have access to the file apache/conf/httpd.conf, open that file and check if 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.
  6. If you think this 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.
  7. 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.