2017-08-28 115 views
2

从URL与图案 -htaccess何时URL重定向?查询字符串

http://example.com/top-100-selenium-interview-questions-answers.html?format=pdf

我想重定向到

的http:// example.com/istqb_dump.pdf

我已经创建了下面的规则重定向。

RewriteCond %{QUERY_STRING} format=pdf [NC] 
RewriteRule .* http:// example.com/istqb_dump.pdf? [R=301,L] 

它工作正常。

现在还有其他的URL,以及像下面 -

http://example.com/top-35-seo-interview-questions/?format=pdf

http://examplecom/top-15-digital-marketing-interview-questions/?format=pdf

,我想重定向到相应的网址实况

HTTP://example.com/seo.pdf

的http:// example.com/digital-marketing.pdf

但上述规则,所有网址都重定向到

的http:// example.com/istqb_dump.pdf

如何配置企业重定向?

+0

更具体和你让你的重写规则匹配...? – CBroe

+0

我想重定向从url - http://example.com/top-100-selenium-interview-questions-answers.html?format=pdf 到此网址 http://example.com/istqb_dump.pdf 请告诉我.htaccess规则。 –

回答

1

你需要让你RewriteRule更具体的,每个案例创建一个定制的条件:

RewriteCond %{QUERY_STRING} format=pdf [NC] 
RewriteRule ^top-100-selenium-interview-questions-answers.html /istqb_dump.pdf? [R=301,L] 

RewriteCond %{QUERY_STRING} format=pdf [NC] 
RewriteRule ^top-35-seo-interview-questions/? /seo.pdf? [R=301,L] 

RewriteCond %{QUERY_STRING} format=pdf [NC] 
RewriteRule ^top-15-digital-marketing-interview-questions/? /digital-marketing.pdf? [R=301,L] 

演示在这里:http://htaccess.mwl.be?share=97bf4828-2ec0-551e-8bc1-4fb9f2f0f278

相关问题