Actions

Enabling Search Engine Friendly (SEF) URLs

From Joomla! Documentation

Revision as of 16:17, 18 March 2013 by Jamil-mohammadi (Talk | contribs)

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

Contents

Apache

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.

First, be sure that your Apache config file allows .htaccess overrides. In the 'Directory' section of your virtual host you MUST have this directive:

 AllowOverride all

If this is not present, the .htaccess file in your Joomla! root directory WILL BE IGNORED.

  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.


IIS 7

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.

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

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.

GUI

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.

In the Joomla config turn on both the SEF and Apache mod_rewrite, next create a rule under IIS URL Rewrite:

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

web.config

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, check out http://learn.iis.net/page.aspx/557/translate-htaccess-content-to-iis-webconfig/

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

  • Please add the next code to your server (vhost) configuration in nginx.conf file:
        # Support Clean (aka Search Engine Friendly) URLs</tt>
        location / {
                try_files $uri $uri/ /index.php?q=$request_uri;
        }
  • If the above will not work try add the next code to your server configuration in nginx.conf file:(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 Back-end 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.
    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)?
  • 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 enabled, leave this option off. It does not matter if you leave the .htaccess file renamed.
  • 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.
  • 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.