ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Mod_Rewrite Regular expressions in EE (where to add?)

November 19, 2012 7:57pm

Subscribe [1]
  • #1 / Nov 19, 2012 7:57pm

    dhjones

    25 posts

    I have the following default EE .htaccess.

    <IfModule mod_rewrite.c>
    
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    RewriteBase /
    
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/system/.*
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
    
    # Standard ExpressionEngine Rewrite
    # ------------------------------
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    </IfModule>

    I need to be able still have my old redirects working when I relaunch my site in EE, so I have some parts I need to strip from the url!


    My old urls are like…

    domain.com/xx/xx/channel/category/url-title-aNUMBER and next is where it should go to…

    <a href="http://www.domain.com/en/us/toys/teddies/teddy-a120">http://www.domain.com/en/us/toys/teddies/teddy-a120</a> -> needs to reach -> <a href="http://www.domain.com/toys/teddies/teddy">http://www.domain.com/toys/teddies/teddy</a>

    or these

    <a href="http://www.domain.com/en/us/contact">http://www.domain.com/en/us/contact</a> -> needs to reach <a href="http://www.domain.com/contact">http://www.domain.com/contact</a>
    <a href="http://www.domain.com/contact">http://www.domain.com/contact</a> -> <a href="http://www.domain.com/contact">http://www.domain.com/contact</a>
    <a href="http://www.domain.com/gh/zn/swimwear-womens/blue/blue-bikini-a11">http://www.domain.com/gh/zn/swimwear-womens/blue/blue-bikini-a11</a> -> <a href="http://www.domain.com/swimwear-womens/blue/blue-bikini">http://www.domain.com/swimwear-womens/blue/blue-bikini</a>


    So as you can see, I want to strip the first two pairs of /(a-zA-Z{2})/(a-zA-Z{2}/ from a url and then if a url ends with -a(0-9) where 0-9 could be up to 3/4 figures!


    Category and channel names can/may contain different cases, and also a - character in EE style.

    Also, do I want these to be 301 redirects?


    If anyone is able to help I would be delighted! Where do I add mod_rewrites to the file, and how come none I try work! :(

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases