Search code examples
mod-rewriteexpressionengine

remove index.php but keep first segment expression engine


I'm doing my first expression engine site.. and i want to remove the index.php.. i read a lot and tried the basic expression engine rewrite "removal" but because i redirect my site depending of the language.. i'm pretty sure there's a better way! i have a lang prefix before the index.php like : domain.com/en/index.php/segment1/.... for now i use :

RewriteCond $2 !\.(index|css|js|gif|jpe?g|png|robot.txt|sitemap.xml) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)?/([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?$ /$1/index.php?/$2/$3/$4/$5 [L]

is there a nicer or better way!?

It's working, but if i have more than 4 segment i'll have to add a $6 and so on.. sure there's a better way...

Regards..

Ben

EDIT:

I still have 1 problem with ChannelImages (DevDemon) and/or ChannelFiles.. i need to test the upload location with domain.com/?ACT=XX xx is a number..

i tried to add RewriteCond %{REQUEST_URI} !^(ACT=.*)$ [NC]

for now the page is redirect to the home page.. /fr or /en..


Solution

  • Assuming the incoming URL structure is always something like this:

    http://domain.com/LangCode/anything

    where LangCode and anything are variables, you may try this in one .htaccess file in root directory:

    Options +FollowSymlinks -MultiViews
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI}  !\.(index|css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_URI}  !(robot.txt|sitemap.xml)        [NC]
    RewriteCond %{REQUEST_URI}  !index\.php                     [NC]
    RewriteRule ^([^/]+)/(.*)/?$  /$1/index.php?/$2             [NC,L]
    

    Maps silently to:

    http://domain.com/LangCode/index.php?/anything

    For permanent and visible redirection, replace [NC,L] with [R=301,NC,L]