.htaccess 301 Redirect with spaces and quotes - still not working

I am having a spot of bother with a 301 Redirect via .htaccess, the whole website has just redevloped in WordPress from an "old skool" Perl system from like 10 years ago.

So now we need to redirect the masses of old pages to the new more friendlier and concise ones.

So I have this as my .htaccess :

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# 301's from OLD site

Redirect 301 "/cgi-bin/utile_cat.pl?cat=1.AIR / GAS COMPRESSORS" "http://www.utileengineering.co.uk/products/air-gas-compressors/"

# END 301's

For some reason going to: DOMAIN.CO.UK/cgi-bin/utile_cat.pl?cat=1.AIR / GAS COMPRESSORS will not redirect to the new URL. In firefox it pushes the perl file download which doesn't exist and in other browsers I get the WP 404 page?

I have tralled through may blog posts, forum posts, stackoverflow posts and they all say the same thing... my issue is completely different by the looks of it.

Does anyone have any idea? The hosting is Fasthosts.

The URL is there inside the code snippet above if you need to have a look to see what is going on.

Thanks for your time!

Upvotes: 0

Views: 1738

Answers (2)

Olivier Pons
Olivier Pons

Reputation: 15778

One of my suggestions is always to use homogeneous tools. I.e. if you use RewriteRule keep using RewriteRule and don't mix with Redirect. This is harder to read for someone else. Stay homogeneous.

You want to redirect? Do like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # 301's from OLD site
    RewriteCond %{QUERY_STRING} cat=1.AIR%20/%20GAS%20COMPRESSORS
    RewriteRule ^cgi-bin/utile_cat\.pl$ /products/air-gas-compressors/? [R=301,L]

</IfModule>

Ain't that much nicer, shorter & maintainable?

And now two hints:

Please try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My favorite tool to check for regexp:

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

May I ask you to add the rewritelog in your question?

Upvotes: 3

CedX
CedX

Reputation: 3977

I think that your URL must be encoded in order to function properly (note the %20 instead of spaces) :

Redirect 301 "/cgi-bin/utile_cat.pl?cat=1.AIR%20/%20GAS%20COMPRESSORS" "http://www.utileengineering.co.uk/products/air-gas-compressors/"

The order of the statements is also important. Perhaps, you should move the 301 redirect to the top in order to be processed before WordPress rewriting rules.

Upvotes: 0

Related Questions