繁体   English   中英

.htaccess 301重定向到Wordpress的参数?

[英].htaccess 301 Redirection Parameter to Wordpress?

我已经将我们的网站之一从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

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

我将我的products_promoDC.php重定向到/product-category/因此仅将变量/参数加载到( /product-category/Corporate+Clothing/ )之后,由于URL中的加号( + ),这仍然给我404错误。 然后,我简单地编写了一个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

关于什么

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

如果您不熟悉htaccess,建议您使用htaccess生成器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM