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.

.htacsess remove url segement

February 21, 2012 12:40pm

Subscribe [2]
  • #1 / Feb 21, 2012 12:40pm

    Kaspar

    30 posts

    Yes I know there are lots of informations about this. I couldn’t get anything to work.

    I have a few dead links because I once had a Multilang Addon installed which left behind a Language url segment and some external links are targeting this dead url. So I want to redirect them to the url without the language segment.

    The Url with the Language segment looks like this:

    http://toplevel.com/en/segement1/segement2/segement3

    So I want to remove the /en/ segment from the url.

    I Already have the index.php removed with:

    RewriteEngine On
         
                 # Removes index.php
                 RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
                 RewriteCond %{REQUEST_FILENAME} !-f
                 RewriteCond %{REQUEST_FILENAME} !-d
                 RewriteRule ^(.*)$ index.php/$1 [L]

    I tried already lots of code snippets from the Web but none worked so far.

    Thanks for your help.

     

  • #2 / Feb 21, 2012 5:03pm

    glenndavisgroup

    436 posts

    Hi Kaspar,

    Try the following:

    RewriteEngine On
         
    # Remove the /en/ from the URL and set a 301 permanent redirect for any URLs using it
    RewriteRule ^en/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ <a href="http://toplevel.com/$1/$2/$3">http://toplevel.com/$1/$2/$3</a> [R=301,NC,L]
    
    # Removes index.php
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    I hope that helps.

    Mike

  • #3 / Feb 22, 2012 4:38am

    Kaspar

    30 posts

    Thanks a lot.

    It works like a charm 😊

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

ExpressionEngine News!

#eecms, #events, #releases