This week I had a URL rewrite/forwarding issue with one of the websites that I created. The site was rebuilt in WordPress from a static HTML website. The client wanted to make sure that old links took people to an appropriate page or similar page on the new site which now had new or different url’s. So we have created several rewrite rules in the .htaccess file (this is a file that has several settings and configurations for this site). Everything worked great for all of the links except for 2 new ones that they gave me. The links looked something like: http://www.website.com/index.html?234ILMO2352DD. They wanted these two links to go to the home page. So I added these redirects like the others but it didn’t work. No matter what I tried it didn’t work. I also went up to http://www.stackoverflow.com to find some input from other engineers. My question on that site is here: http://stackoverflow.com/questions/13771068/htaccess-redirect-301-not-working-with-arguments. Feedback and suggestions came in pretty quickly. I tried everything and still nothing worked. Contributors and I were very confused why it wasn’t working. So I went back in the file and decided to try and move some lines of code later in order.
# suExec for PHP Action application/x-pair-sphp /cgi-bin/php5.cgi AddType application/x-pair-sphp .php #Video MIME Types: AddType video/m4v .m4v AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /director/ RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress redirect 301 /pages/laser.html http://www.joiningtech.com/pages/welding.html redirect 301 /index_nosound.html http://www.joiningtech.com/ RewriteEngine On RewriteCond %{REQUEST_URI} =/index.html [NC] RewriteCond %{QUERY_STRING} =GAW+CAM2&gclid=CNbT06iehLQCFQWe4AodejAAkA [OR] RewriteCond %{QUERY_STRING} =GAW+CAM2&gclid=CMncjs-ehLQCFdKd4Aod52AAAQ RewriteRule .* http://www.joiningtech.com/? [L,R=301] <ifModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" </ifModule>
I changed the code order to:
# suExec for PHP Action application/x-pair-sphp /cgi-bin/php5.cgi AddType application/x-pair-sphp .php #Video MIME Types: AddType video/m4v .m4v AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm redirect 301 /pages/laser.html http://www.joiningtech.com/pages/welding.html redirect 301 /index_nosound.html http://www.joiningtech.com/ RewriteEngine On RewriteCond %{REQUEST_URI} =/index.html [NC] RewriteCond %{QUERY_STRING} =GAW+CAM2&gclid=CNbT06iehLQCFQWe4AodejAAkA [OR] RewriteCond %{QUERY_STRING} =GAW+CAM2&gclid=CMncjs-ehLQCFdKd4Aod52AAAQ RewriteRule .* http://www.joiningtech.com/? [L,R=301] # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /directory/ RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress <ifModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" </ifModule>
It now works. So I’m going to have to remember that there are ordering issues with these types of things.