2016-01-08 13 views
1

https://example.com/art/img/art_print/7d49524f7273563bf4aadb3986eb63a5.jpg/?pid=1234我如何在我的htaccess文件中重定向像這樣的網址?

https://example.com/art/img/art_print/7d49524f7273563bf4aadb3986eb63a5.jpg?pid=1234(不帶/前?)

注:後的值 「art_print /」 改變

當前htaccess的文件

# Protect files and directories from prying eyes. 
<FilesMatch "\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$"> 
    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 

#compress certain files 
<FilesMatch "\\.(js|css|html|htm|php|xml)$"> 
    SetOutputFilter DEFLATE 
</FilesMatch> 

# Make Drupal handle any 404 errors. 
ErrorDocument 404 /index.php 

# Force simple error message for requests for non-existent favicon.ico. 
<Files favicon.ico> 
    # There is no end quote below, for compatibility with Apache 1.3. 
    ErrorDocument 404 "The requested file favicon.ico was not found. 
</Files> 

# Set the default handler. 
DirectoryIndex index.php 

# Override PHP settings. More in sites/default/settings.php 
# but the following cannot be changed at runtime. 

# PHP 4, Apache 1. 
<IfModule mod_php4.c> 
    php_value magic_quotes_gpc    0 
    php_value register_globals    0 
    php_value session.auto_start    0 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_value mbstring.encoding_translation 0 
</IfModule> 

# PHP 4, Apache 2. 
<IfModule sapi_apache2.c> 
    php_value magic_quotes_gpc    0 
    php_value register_globals    0 
    php_value session.auto_start    0 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_value mbstring.encoding_translation 0 
</IfModule> 

# PHP 5, Apache 1 and 2. 
<IfModule mod_php5.c> 
    php_value magic_quotes_gpc    0 
    php_value register_globals    0 
    php_value session.auto_start    0 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_value mbstring.encoding_translation 0 
    php_value post_max_size     300M 
    php_value memory_limit     1000M 
    php_value upload_max_filesize    300M 
    php_value max_execution_time    600000000 
    php_value session.hash_bits_per_character    4 
    php_value session.save_path "/var/lib/php5" 
    #php_admin_flag engine on 
    php_flag xcache.cacher 1 
    php_flag xcache.optimizer 1 
    #php_flag eaccelerator.enable 1 
    #php_flag eaccelerator.optimizer 1 
</IfModule> 

# Requires mod_expires to be enabled. 
<IfModule mod_expires.c> 
    # Enable expirations. 
    ExpiresActive on 
    ExpiresByType image/jpeg A604800 
    ExpiresByType image/gif A604800 
    ExpiresByType image/png A604800 
    ExpiresByType application/x-shockwave-flash A604800 
    ExpiresByType audio/mpeg A604800 

    # Cache all files for 0 weeks after access (A). 
    # ExpiresDefault "access plus 3 days" 

    #Caching Removed 
    ExpiresDefault A1 
    Header unset Cache-Control 
    Header append Cache-Control: "no-cache,must-revalidate" 

    # Do not cache dynamically generated pages. 
    #ExpiresByType text/html A1 
</IfModule> 

# Various rewrite rules. 
<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule (^|/)wp-login\.php(/|$) /? [L,NC,R=301] 



    RewriteCond %{THE_REQUEST} ^.*/index.html 
    RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L] 

    RewriteCond %{HTTP_HOST} ^example\.com [NC] 
    RewriteRule ^(.*) http://www.example.com/$1 [R=301,L] 



    RewriteBase/

    RewriteCond %{HTTPS} off 
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 



</IfModule> 

回答

1

插入這條規則剛好在RewriteEngine On以下:

RewriteRule ^(art/img/art_print/.+\.jpg)/$ /$1 [L,NC,R=302] 

並在清除瀏覽器緩存後進行測試。

+0

我試圖添加到我的htaccess,但它只是導致重定向到_https://www.example//art/img/art_print/7d49524f7273563bf4aadb3986eb63a5.jpg?q = art/img/art_print/7d49524f7273563bf4aadb3986eb63a5.jpg/&pid = 1118045709 – AllisonC

+1

工作正常,謝謝。 – AllisonC