Search code examples
.htaccessmod-rewriteexpressionengine

mod rewrite .htaccess expressionengine remove index.php and a specific subdirectory


Hate to ask this question, but I've been banging my head on the desk for a while and can't seem to get it. I'm using ExpressionEngine, and I'm using mod_rewrite to remove index.php from all of my URLs. That works fine. Additionally, I want anything that is myurl.com/adwords/(anything) to be rewritten to myurl.com/(anything). My regex and htaccess skillz are weak. Here is what I have in .htaccess:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/adwords/(.*)$
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

So I think I'm saying anything that ends in /adwords/(something), capture the something, and then append it at the end of index.php via $1. I'm guessing this is simple. Thanks!


Solution

  • The rule you are looking for as such is probably simply

    RewriteRule ^adwords/(.*)$ index.php/$1 [L]
    

    with no rewrite condition needed, but I wonder... do you really want to rewrite http://myurl.com/adwords/foo to http://myurl.com/index.php/foo, rather than to http://myurl.com/index.php?a=foo ?

    If you also want to rewrite something like http://myurl.com/baa/adwords/foo to http://myurl.com/baa/index.php/foo, you have to omit the ^:

    RewriteRule adwords/(.*)$ index.php/$1 [L]
    

    BTW, you can test most of your rewrite rules here: http://htaccess.madewithlove.be/