Enabling Search Engine Friendly (SEF) URLs

From Joomla! Documentation

Revision as of 12:21, 26 March 2013 by Chris Davenport (talk | contribs) (Reverted edits by Deadjdona (talk) to last revision by Jamil-mohammadi)

<translate> 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. </translate>

The procedure for enabling Search Engine Friendly URLs differs depending on the web server you are using. If you are using shared hosting, it is probably Apache. Ask your hosting provider for more information if you are uncertain.

Only the most popular web servers have been included on this page. Visit Enabling Search Engine Friendly (SEF) URLs on IIS and Category:Search Engine Friendly URLs for more articles.

Apache[edit]

<translate>

Verify .htaccess is Enabled[edit]

</translate> <translate> 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:</translate>

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

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

<translate> 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.</translate>

<translate> ==Step by Step== </translate> <translate> 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.</translate> <translate>

  1. Rename the file htaccess.txt in your Joomla root folder to .htaccess.</translate>

<translate>

  1. 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, enter the Joomla folder name after the forward slash. e.g. RewriteBase /yourjoomlafolder.</translate>

<translate>

  1. Log on to your Backend and open the Global Configuration.</translate>

<translate>

  1. 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>

  1. Check if 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, see How to check if mod rewrite is enabled on your server.</translate>

<translate>

    • 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.</translate>

<translate>

    • If mod_rewrite cannot be enabled, leave this option off. It does not matter if you leave the .htaccess file renamed.</translate>

<translate>

  1. 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.</translate>

<translate>

  1. 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>


IIS 7[edit]

<translate> If you have a server running IIS 7 and PHP, you can take advantage of IIS's own internal URL rewriting by using a web.config file similar to the one listed below.</translate>

<translate> You can create the file yourself or use the GUI in the IIS7 Manager. You can import .htaccess rules using the GUI/wizard.</translate>

<translate> This functionality depends on the presence of the IIS URL Rewrite Module, which does not come with Windows. It is a free download and a Microsoft product.</translate>

<translate> ===GUI=== </translate> <translate> If the IIS URL Rewrite module is installed, your website manager will have a tool for URL Rewrite, visible in the IIS Manager's view of your site's configurable IIS modules. The interface is largely self-explanatory. Regular expressions, wildcards or exact matches are all supported.</translate>

<translate> In the Joomla config turn on both the SEF and Apache mod_rewrite. Next create a rule under IIS URL Rewrite:</translate>

Pattern field: ^([^/]+)/?$
Ignore case ON
Action type: Rewrite
Rewrite URL: index.php/

<translate>=== web.config === </translate> <translate> This has been tested on Joomla 1.5 with IIS 7 on Windows Server 2008 with no problems so far. For more information on converting .htaccess to web.config, see Translate .htaccess Content to IIS web.config</translate>

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Common Exploit Blocking" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" />
                        <add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" />
                        <add input="{QUERY_STRING}" pattern="(\&lt;|%3C).*script.*(\>|%3E)" />
                        <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" />
                        <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" />
                    </conditions>
                    <action type="Redirect" url="index.php" appendQueryString="false" redirectType="SeeOther" />
                </rule>
                <rule name="Joomla Search Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="^/search.php" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.php?option=com_content&amp;view=article&amp;id=4" />
                </rule>
                <rule name="Joomla Main Rewrite Rule" stopProcessing="true">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="(/[^.]*|\.(php|html?|feed|pdf|raw))$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/" />
                </rule>
            </rules>
        </rewrite>
        <caching>
            <profiles>
                <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
            </profiles>
        </caching>
    </system.webServer>
</configuration>


Nginx[edit]

<translate>

  • Please add this code to your server (vhost) configuration in the nginx.conf file:</translate>
   # <translate>Support Clean (aka Search Engine Friendly) URLs</translate>
   location / {
      try_files $uri $uri/ /index.php?$args;
   }

<translate>

  • 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>
server {
  ....
  location / {
     expires 1d;

     # Enable joomla SEF URL's inside Nginx
     try_files $uri $uri/ /index.php?$args;
  }
  ....
}

<translate>

  • Log on to your Backend and open the Global Configuration.</translate>

<translate>

  • 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>

  • 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.</translate>

<translate>

<translate>

  • 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>

  • 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.</translate>

<translate>

<translate>

  • 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>

  • If mod_rewrite cannot be enabled, leave this option off. It does not matter if you leave the .htaccess file renamed.</translate>

<translate>

  • 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>

  • 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>