Views: 4577 (Data available since 06.02.2017)
Last Modified: 10.10.2012

As of version 5.1.8 and higher, the system kernel is empowered with the redirection mechanism which is used to support SEF URL (Search Engine Friendly URL).

URL Rewrite

URL Rewrite enables a page to respond not only at a physical address, but also at any other requested URL. For example, you can configure the URL processing settings to make /fld/c.php that respond at:

   /fld/c.php?id=15

respond also at:

   /catalog/15.php

The URL at which a page responds must not exist on a server. If it does, the system will return a page that exists at this URL, and no URL rewrite will take place.

The URL rewrite rules can be are configured in /bitrix/admin/urlrewrite_list.php.

The URL rewrite mechanism has been developed mainly for components 2.0 supporting SEF URL. However, this feature can be used to redefine any other URL.

When adding to a page a SEF URL enabled component, a URL rewrite rule is created automatically (if the file is saved using system API). Otherwise, (for example, when uploading files via FTP), you have to re-create the rules (use the toolbar button on the rule configuration page).

Enabling the URL rewrite mechanism

  1. If the 404 error processing is enabled for Apache, the ErrorDocument option or similar instruction exists in .htaccess:

       ErrorDocument 404 /404.php,

    Edit the file 404.php by typing the following command at the beginning of the file:

       include_once( $_SERVER['DOCUMENT_ROOT']. '/bitrix/modules/main/include/urlrewrite.php' );

  2. If Apache used the mod_rewrite module, specify the following instructions (for example, in the file .htaccess):

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
    RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
    </IfModule>

    Once you have made the described changes, the standard SEF support will be enabled.

Simple test to verify the URL Rewrite settings

  1. Open Settings –> Product settings –> URLs processing:

    Click on image to enlarge

  2. Click New record, select the required site and fill in the form:
    Condition: #^/sef_test/# 
    Component: none
    File: /index.php (or specify a required file)
    Rule: none

    Save changes.

  3. Open a page in the directory /sef_test/.
    For example: http://localhost/sef_test/test.html.

    If SEF URL is in effect, you will see the contents of a page specified in the File field.

Examples

  1. If the following rule exists:

       Condition = #^/gallery/#
       File = /max/images/index.php

    and a visitor requests the page /gallery/38.php that does not exist, the URL rewrite system will return the page /max/images/index.php.

  2. If the following exists:

       Condition = #^/index/([0-9]+)/([0-9]+)/#
       Rule = mode=read&CID=$1&GID=$2
       File = /newforum/index.php

    and a visitor requests /index/5/48/, the system will return /newforum/index.php?mode=read&CID=5&GID=48.

  3. The following rule:

       Condition = #(.+?)\\.html(.*)#
       Rule = $1.php$2

    returns /about/company.php?show in reply to a request for /about/company.html?show.



Courses developed by «Bitrix», Inc.