Home .htaccess 301 Redirection Parameter to Wordpress?
Reply: 2

.htaccess 301 Redirection Parameter to Wordpress?

Daniel Crouse
1#
Daniel Crouse Published in 2015-04-22 11:13:36Z

I have migrated one of our sites from a PHP coded website to a WordPress website and I am having a problem with redirecting the old shop pages to our new shop pages.

I would like to do a 301 Redirect for this link:

http://www.example.com/products_promoDC.php?Product_Category=Corporate+Gifts

to:

http://www.example.com/product-category/corporate-gifts/

Everything I add does not work at all.

Currently I have:

# 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

# GZIP COMPRESSION
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# END GZIP COMPRESSION

Any help would be greatly appreciated!

EDIT

I have changed my .htaccess code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^Product_Category=Corporate+Gifts$ [NC]
RewriteRule ^products_promoDC\.php http://www.example.com/product-category/corporate-gifts? [L,R=301]

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

# END WordPress
pbalazek
2#
pbalazek Reply to 2015-04-22 12:00:21Z

What about

RedirectMatch 301 ^/products_promoDC\.php\?Product_Category\=Corporate\+Gifts/(.*)$ /product-category/corporate-gifts/$1

If you're new to htaccess, I recommend you to use htaccess generator

MrWhite
3#
MrWhite Reply to 2015-10-29 15:29:24Z

So I solved my own problem.

I redirected my products_promoDC.php to /product-category/ so the Variable/Parameter is then only loaded behind (/product-category/Corporate+Clothing/) this still gave me a 404 error because of the plus (+) within the URL. I simply then wrote a RewriteRule to convert the pluses (+) to dashes!

RewriteRule "^([^+]*)\++([^+]*\+.*)$" /$1-$2 [N]
RewriteRule "^([^+]*)\++([^+]*)$" /$1-$2 [L,R=301]

RewriteCond %{QUERY_STRING} Product_Category=([^&]+) [NC]
RewriteCond %{QUERY_STRING} Product_Subcategory=([^&]+) [NC]
RewriteRule products_promoDC\.php product-category/%1/? [L,R=301]

I added a second line for my subcategories to load as well!

Working perfectly:

http://www.example.com/products_promoDC.php?Product_Category=Corporate+Gifts
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.380585 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO