我一直在研究这个问题几个小时,似乎无法找到解决这个问题的有效方法。我创建了从/sites/default/files/OLB%20Registration%20Guide.pdf
到/sites/default/files/downl_section/Online-Banking-Registration-Guide.pdf
的重定向,但无效。
以下是.htaccess
Redirect 301 "/sites/default/files/OLB Registration Guide.pdf" /sites/default/files/downl_section/Online-Banking-Registration-Guide.pdf
我的第一个倾向是删除%20
,但仍然没有...有没有人知道如何创建原始网址包含%20
的重定向?
谢谢!
.htaccess
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig\.save)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
# Etags
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
Header unset ETag
FileETag None
</FilesMatch>
# Jan 10 2018
Redirect 301 /cards https://company.org/login?utm_campaign=creditcard-mastercard&utm_source=directmail
# feb 09
Redirect 301 /bgvisa /BGMasterCard
# jan 2015
Redirect 301 /qchoice /checking
# july 1
Redirect 301 /mobileapps /anywherebanking#tab-1
# pdfs
Redirect 301 "/5001-01-NEWcompany/UserFiles/file/Quicken and MS Money Resource Document.pdf" /sites/default/files/files/Quicken.pdf
Redirect 301 "/5001-01-NEWcompany/UserFiles/file/membership app_Minor_cp.pdf" /sites/default/files/files/custodial_app.pdf
Redirect 301 "/UserFiles/File/ONLINE DEPOSITS FAQ_NEW.pdf" /sites/default/files/files/ONLINE%20DEPOSITS%20FAQ_NEW.pdf
...more redirects...
# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php index.html index.htm
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
</FilesMatch>
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.company.org/$1 [R,L]
# Set "protossl" to "s" if we were accessed via https://. This is used later
# if you enable "www." stripping or enforcement, in order to ensure that
# you don't bounce between http and https.
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
# rewrite documents path
RewriteCond %{QUERY_STRING} =v=36d38d70-92ae-47e4-97a9-569a741557c4
RewriteRule ^default\.aspx$ /why-company/careers/? [L,R=301]
RewriteCond %{QUERY_STRING} =v=ae2715bb-8e70-4e7f-9b47-1607a62b9db4
RewriteRule ^default\.aspx$ /contact-us/? [L,R=301]
RewriteCond %{QUERY_STRING} =v=69940420-9499-452d-ba52-f40d6f03bcfb
RewriteRule ^default\.aspx$ /why-company/recent-events/? [L,R=301]
RewriteCond %{QUERY_STRING} =v=9ceaa473-41e1-49e2-8db8-a4a907b8f18e
RewriteRule ^default\.aspx$ /services/atmbranchlocator/? [L,R=301]
RewriteCond %{QUERY_STRING} =v=95d869d3-f576-4c1d-a467-b46ea9691c97
RewriteRule ^default\.aspx$ /sites/default/files/files/QFCU_2012_Annual_Report.pdf? [L,R=301]
... more rewritecond / rewriterules...
RewriteRule ^sweepstakesrules?$ "/sites/default/files/files/MasterCard/Official Rules.pdf" [L,NC]
RewriteRule ^March2014?$ /sites/default/files/files/March2014.pdf [L,NC]
RewriteRule ^browsersupport?$ /sites/default/files/files/browsersupport.pdf [L,NC]
RewriteRule ^QuickenInstructions?$ /sites/default/files/files/Quicken_conversioninstructions_Final.pdf [L,NC]
RewriteRule ^servicedowntime?$ "/sites/default/files/downl_section/Service Downtime Chart.pdf" [L,NC]
# Make sure Authorization HTTP header is available to PHP
# even when running as CGI or FastCGI.
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# If you do not have mod_rewrite installed, you should remove these
# directories from your webroot or otherwise protect them from being
# downloaded.
RewriteRule "(^|/)\." - [F]
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
答案 0 :(得分:1)
试试这个:
RedirectMatch 301 (/sites/default/files/)(OLB.*)(Registration)(.*)(Guide\.pdf)$ $1downl_section/Online-Banking-$3-$5
注意:清除浏览器缓存然后测试
答案 1 :(得分:1)
您可以使用mod-rewrite
进行此重定向
RewriteEngine on
RewriteCond %{THE_REQUEST} /sites/default/files/OLB%2520Registration%2520Guide\.pdf [NC]
RewriteRule ^.+$ /sites/default/files/downl_section/Online-Banking-Registration-Guide.pdf [L,R]