Search code examples
.htaccesshttp-redirectexpressionengine

Expression Engine built in redirects?


I just rebuilt one of our websites in Expression Engine and everything has been going great! I needed to create a bunch of redirects to hopefully fix some old URL's from the previous site.

Example:

The old site created URL's like: index.php?id=30

this one for instance needed to be redirected to: http://www.example.com/contact

So in my .htaccess I created:

Redirect /index.php?id=30 http://www.example.com/contact

I did this about 50 times for all the various ID's. However, when I go to these links, they just drop me on the homepage and keep the URL how it was. (www.example.com/index.php?id=30).

Then I noticed it doing this for ANY URL that doesn't exist. So I could type in:

www.example.com/asdasdjasdbjhasdbjhasdbjhasdbjhasdbjhasd

and it simply drops me on the homepage.

Here is what else I have in my .htaccess file with some examples of redirects. This first bit just removes the /index.php from the URL's.

RewriteEngine On

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

Redirect /index.php?id=30 http://www.example.com/contact

Redirect /index.php?id=26 http://example.com/careers

Redirect /index.php?id=28 http://example.com/about

So what is going on here, does Expression Engine have built in redirects that are breaking my redirects?

Thanks for the help!


Solution

  • You can't match against the query string in a Redirect statement, you need to use a RewriteCond and match against the %{QUERY_STRING} variable. Make sure to add these rules BEFORE your expression engine rules:

    RewriteCond %{QUERY_STRING} ^id=30
    RewriteRule ^/?index.php$ http://www.example.com/contact [L,R]
    RewriteCond %{QUERY_STRING} ^id=26
    RewriteRule ^/?index.php$ http://www.example.com/careers [L,R]
    RewriteCond %{QUERY_STRING} ^id=28
    RewriteRule ^/?index.php$ http://www.example.com/about [L,R]
    

    etc.