Makes your URLs both search engine and user friendly
Author: Trustmaster
Submitted by: Trustmaster
Date: 2008-06-04 09:50
Comments: (0)
Ratings:
 
Welcome to advanced Seditio Rewrite extension which makes your URLs both user and search engine friendly. First I need to say that you should be rather patient and experienced Seditio admin in order to use this extension.

Features:


Requirements:

    1. Apache users: mod_rewrite should be installed and enabled before using this plugin.
    2. Microsoft IIS users should install Ionic's Isapi Rewrite Filter
    3. Nginx users should be able to edit server configuration.


Installation:
You must be attentive to follow all the instructions given, otherwise you may fail with no result or even cause damage to your Seditio source tree.

    1. Download and install Seditio Patcher Tool (http://www.seditioforge.com/plugins/administration/code-patcher-tool-i47.html). It is used during the installation process. Or you can do patching manually (see step 9).

    2. Download the Rewrite extension (see the link below) and unpack it into a temporary location. Put the 'plugins/rewrite' folder into your Seditio 'plugins' folder. Put 'system/rewrite.php' into your Seditio 'system' folder. It is safe to install the plugin now, it just won't work until you finish the installation.

    3. Now log into your Seditio admin panel and do not logout until the installation is finished.

    4. Open 'patches/common.hook.txt'. Put its contents right before the following code in system/common.php:

    PHP Code:


    /* ======== Anti-XSS protection ======== */

    $xg = sed_import('x','G','ALP');
    $xp = sed_import('x','P','ALP');

    $xk = sed_check_xp();
     


    So that it becomes:

    PHP Code:


    /* === Hook === */
    $extp = sed_getextplugins('input');
    if (is_array($extp))
    { foreach($extp as $k => $pl) { include('plugins/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php'); } }
    /* ======================== */

    /* ======== Anti-XSS protection ======== */

    $xg = sed_import('x','G','ALP');
    $xp = sed_import('x','P','ALP');

    $xk = sed_check_xp();
     


    5. Open your 'system/functions.php'. Find sed_javascript function and replace it with one found in 'patches/functions.sed_javascript.txt'. Then go to the bottom of 'system/functions.php' and just before "?>" add the code from 'patches/functions.bottom.txt'.

    6. In order for popups to work, you need to modify 2 files more. Open your 'system/core/pfs/pfs.inc.php' and find the code beginning with
    PHP Code:


    $pfs_header1 = $cfg['doctype']."<html><head>
    <title>"
    .$cfg['maintitle']."</title>".sed_htmlmetas()."

    and ending with
    Code:
    //-->
    </script>
    ";

    Replace it with the code provided in 'patches/pfs.pfs_header1.txt'.

    7. Open 'system/core/polls/polls.inc.php' and find the code beginning with
    PHP Code:


    $polls_header1 = $cfg['doctype']."<html><head>
    <title>"
    .$cfg['maintitle']."</title>".sed_htmlmetas()."

    and ending with
    Code:
    //-->
    </script>";

    Replace it with the code provided in 'patches/polls.polls_header1.txt'.

    8. Now go to your admin.php?m=plug and install the Rewrite Extension. Note that any redirect attempts will give you 404 error right after plugin is installed. Also no URLs will have been changed yet.

    9. There are 2 ways to solve the redirect problem.
    9.1. If you have successfully installed the Patcher Tool go to Admin -> Tools -> Patcher Tool. Enter patching parameters as follows. Find: "#\sheader\(#" (without quotes). Replace: " sed_header(" (without quotes). Push the "Scan" button. If the scanner tells that some files are not writable, set the appropriate chmods to them and their folders (you may set them back after patching). When done with chmods, click the "Patch" button. Be careful no to patch 'system/rewrite.php'. Restore it from the package if you have done so.
    9.2. If you don't have the Patcher or it fails to patch, you should patch the files manually. First you need "find-and-replace in files" text editor. Then download your Seditio source tree from server and patch it locally. All you need is to replace the "header" function calls with "sed_header" ones in all of the .php files. So, "Find" is "header(" and "Replace" is "sed_header(". Be careful no to patch 'system/rewrite.php'. Restore it from the package if you have done so. When you are done with patching, upload the files back to your server.

    10. Open 'system/common.php' again. Find the following code:
    PHP Code:


    /* ======== Gzip and output filtering ======== */

    if ($cfg['gzip'])
        { @ob_start('ob_gzhandler'); }
    else
        { ob_start(); }

    ob_start('sed_outputfilters');
     


    And add just a line of code to it:
    PHP Code:


    // Enables rewrite
    ob_start('rewrite_output');
     


    11. Go to your Admin panel -> Plugins and install the Rewrite Extension. Then you need to configure it:
    11.1. Do not enable the rewrite engine until you have changed your .htaccess/.ini (see step 12).
    11.2. Choose rewrite options you want and separators for your URLs. Do not use the same separator for main and name-value.
    11.3. Add more scripts to the lists if your Seditio is non-standard.

    12. Go to your Admin panel -> Tools -> Rewrite Extension and generate your .htaccess/IsapiRewrite4.ini:
    12.1. Apache users. Make sure you have mod_rewrite installed and working. Save generated .htaccess in your Seditio root, or, if your .htaccess is writable, you can do it by clicking an appropriate link below.
    12.2. IIS users. Install free Ionic's ISAPI Rewrite Filter (http://cheeso.members.winisp.net/IIRF.aspx). For instructions see the Readme which comes with it . Put 'IsapiRewrite4.ini' generated by admin tool into the same directory your 'IsapiRewrite4.dll' resides.

    13. Go to Rewrite Extension configuration and enable the rewrite engine.


Updating instructions:

    1.0.1-1.0.2:
    1. Just replace old system/rewrite.php with new file.

    1.0.0-1.0.1:
    1. Just replace old system/rewrite.php with new file.

    0.4-1.0:
    1. Replace plugin and system files and reinstall the plugin in admin panel.
    2. Apply new patches as described in Steps 5, 6, 7 from the "Installation" instructions given above.
    3. Check the plugin configuration and your .htaccess/IsapiRewrite4.ini/nginx.conf.

    0.3-0.4:
    1. Uninstall the plugin in your admin panel and remove old files.
    2. Follow Steps 2, 11, 12 from the "Installation" instructions given above.
    3. Finish with the Step 13. Now you have successfully upgraded.


Updating Seditio:
If you update your Seditio or add new plugins take care of the following things:

    1. Repeat all the manipulations with the source files after upgrading your Seditio.
    2. If installing a new plugin, search its source for header() calls and replace them with sed_header() calls. Do not use the Patcher tool in this case, because it will spoil the sed_header() function itself. Or you may use the Patcher tool, but you need to open the sed_header() function and change all sed_header() calls inside of it back to header() ones right after patching.


Customizing your URLs:

    1. First you should know about switches in Admin panel configuration which control some standard features. When you make any changes in the URL format, disable the rewrite engine when you edit the configuration. Then generate new .htaccess/IsapiRewrite4.ini and enable the engine again after you have applied webserver configuration. Otherwise you may encounter problems by following URLs which haven't yet been accepted by webserver.
    1.1. SHORTCUTS. Whether to use shortcuts when converting URLs. Enabled by default. Switch it off if you don't need shortcut but want better performance. It also switches off the rest extras.
    1.2. EXTRA SEO. Whether to append additional text to the URLs. It doesn't make any sense for Seditio (besides extra database load) but it is significant for search engines.
    1.3. TRANSLIT. Whether to transliterate non-latin characters in extra SEO text. Use for your own risk.
    1.4. CHARSET. Your charset used for transliteration.
    1.5. USERS. Whether to use usernames as shortcuts. Pages of users with latinic names will be accessible at http://yoursite.com/users/UserName.
    1.6. MAIN SEPARATOR. The main URL separator. With rewrite=off it is "?" or "&", default for rewrite is "/".
    1.7. NAME-VALUE SEPARATOR. Secondary URL separator. With rewrite=off it is "=", default for rewrite is "-".
    1.8. SUFFIX. Pages suffix in the url. You may use ".html", ".asp", any other extension or just leave it blank for no suffix at all.

    2. If you have enabled EXTRA SEO, TRANSLIT and filled CHARSET but extra SEO still doesn't work (check forum topics, for example) or adds ????? instead of characters, it means that you don't have iconv extension or iconv cannot transliterate your encoding. In this case you need to write and enable your own translit function. The example with WINDOWS-1251 encoding is given in 'plugins/rewrite/rewrite.php'. After you have your translit function, comment the line with iconv() in rewrite_prep() and add $title = your_translit_function($title), like in example. Don't forget to say the file itself in your encoding!

    3. Still want more custom URLs? Not a problem.
    3.1. First you need to know PHP (http://www.php.net/manual/en/ is a good teacher). Then you need to know PCRE (http://www.php.net/manual/en/reference.pcre.pattern.syntax.php will help). Then you need some basic knowledge of mod_rewrite (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html is all you need).
    3.2. Ready to go? Now open 'system/rewrite.php' and find "Configuration" section in rewrite_output(). Here you can set the delimiters you want and also a page suffix. Note that $rwr_sep and $rwr_psep should be different sequences (otherwise the parser will fail) and you should be aware of RFC 2616 (http://www.w3.org/Protocols/rfc2616/rfc2616.html) when choosing separators.
    3.3. And finally the hardest task. Open your .htaccess files and edit the rules for your new URLs. Usually it means you need to replace old separators with new ones, old .html suffix with yours and don't forget to escape PCRE sequences.

    4. Want your own shortcuts? Not a problem if you are familiar with the fist 3 tricks. Open 'system/rewrite.php', rewrite_output() function and find "Custom shortcuts" section. After you have understood its simple logic, you will be able to add your own shortcuts or change existing ones. And don't forget to add your new rules to .htaccess file.


Changelog:

    1.0.2:
    * A bugfix in sed_header for absolute URLs.

    1.0.1:
    * A fix for EXTRA_SEO titles in system/rewrite.php.

    1.0.0:
    + nginx error_page documents support.
    + no_comments and no_ratings options added to eliminate duplicate pages.
    * Various fixes in page titles and EXTRA_SEO.
    * Stability and performance fixes.

    0.4.3:
    + nginx webserver support.
    * Improved .htaccess/IsapiRewrite4.ini/nginx.conf generator.
    * Plugin compatibility fixes (e.g. T3 Index).
    * More stability.

    0.4.2:
    * Apache 1.3 compatibility.
    * Bugfix in .htaccess generator.
    * Stability fixes for EXTRA SEO.

    0.4.1:
    * PHP4-compatibility fix.

    0.4:
    @ All the configuration/customization has moved to the Admin panel.
    + Automated .htaccess/IsapiRewrite4.ini generator tool.
    * Code optimizations. Thanks to CTAPbIu_MABP for PHP coding lessons.

    0.3.3:
    * Slight optimization.

    0.3.2:
    * Bugfix for users.

    0.3.1:
    + http://yoursite.com/user/UserName user pages instead of http://yoursite.com/u-something.html
    * Performance optimizations.
    * A few bugfixes.
    - User-friendly shortcuts have gone for good (actually, for stability reasons).

    0.3:
    @ New efficient architecture.
    * Speed optimizations.
    * Fixed problems with popups.

    0.2.3:
    + Absolute urls support (converts old absolute urls).
    + Shortcuts to forum pages (t-page_id).
    + More EXTRA_SEO.
    * Fixes for background images and style properties.

    0.2.2:
    * Bugfix in .htaccess/IsapiRewrite4.ini

    0.2.1:
    + Microsoft IIS support (thanks seboo1987 for beta-testing).
    + More EXTRA_SEO.
    + Shortcuts for users.php and homepage-like URLs.
    * Optimizations in rewrite rules.

    0.2:
    + New shortcut engine.
    + New SEO-friendly shortcuts.
    + Shortcuts enabled by default.
    + Extra SEO abilities.
    + Microsoft IIS support (experimental)
    * Fixed a bug in sed_header().


Known problems:

    1. CAPTCHA doesn't work after installing Rewrite Extension. To fix it open your php-captcha.inc.php (usually 'plugins/captcha/inc/php-captcha.inc.ph', but some other plugins use this script as well) and replace all "sed_header" occurances with "header" ones (without quotes). Now your captcha is back.

    2. When a user logs out, immidiate log-in gives "Wrong parameter in the URL" error. To fix this, go admin/m-config/n-edit/o-core/p-main.html and set an appropriate Cookie path. For example, if your Seditio is installed in htdocs root, it's just "/". If it is in "seditio" subfolder, path is "/seditio". Next time a user logs in, the bug is gone.



Download : Advanced Rewrite Extension 1.0.2
Size: 16KB, downloaded 1467 times
Copyright © 2008 Domain.Com. All Rights Reserved.
Page created in 0.56 seconds