将所有pdf重定向到主域

时间:2013-07-26 08:54:39

标签: apache .htaccess redirect

我正在尝试重定向网址,例如:

http://www.example.co.uk/pdfs/example-file.pdf

http://www.example.co.uk/files/example-file.pdf

http://www.example.co.uk/documents/example-file.pdf

到基本域http://www.example.co.uk/

。通过

# PDFs on old site, redirect them
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^/?pdf/(.*)$ http://www.example.co.uk/$1 [R=301,L]
    RewriteRule ^/?files/(.*)$ http://www.example.co.uk/$1 [R=301,L]
    RewriteRule ^/?documents/(.*)$ http://www.example.co.uk/$1 [R=301,L]
</IfModule>
# END PDFs on old site, redirect them

我在哪里错了?

1 个答案:

答案 0 :(得分:1)

正确的规则是:

# PDFs on old site, redirect them
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(/?pdfs/.*)$ http://www.example.co.uk/$1 [R=301,L]
    RewriteRule ^(/?files/.*)$ http://www.example.co.uk/$1 [R=301,L]
    RewriteRule ^(/?documents/.*)$ http://www.example.co.uk/$1 [R=301,L]
</IfModule>
# END PDFs on old site, redirect them