.htaccess 301重定向参数到Wordpress?

时间:2015-04-22 11:13:37

标签: php wordpress .htaccess mod-rewrite redirect

我已经将我们的一个网站从PHP编码网站迁移到WordPress网站,我遇到了将旧商店页面重定向到新商店页面的问题。

我想为此链接执行301重定向:

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

为:

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

我添加的所有内容根本不起作用。

目前我有:

# 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

非常感谢任何帮助!

修改

我已经更改了我的.htaccess代码:

# 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

1 个答案:

答案 0 :(得分:1)

所以我解决了自己的问题。

我将products_promoDC.php重定向到/product-category/,因此变量/参数只会被加载到后面(/product-category/Corporate+Clothing/),因为加号(+,这仍然给我404错误在URL中。我只是写了一个RewriteRule来将加号(+)转换成破折号!

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]

我为子类别添加了第二行也加载了!

完美地工作:

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