如何在我的htaccess文件中重定向这样的网址?

时间:2016-01-08 14:00:11

标签: regex .htaccess

https://example.com/art/img/art_print/7d49524f7273563bf4aadb3986eb63a5.jpg/?pid=1234

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 个答案:

答案 0 :(得分:1)

RewriteEngine On行:

下方插入此规则
RewriteRule ^(art/img/art_print/.+\.jpg)/$ /$1 [L,NC,R=302]

并在清除浏览器缓存后对其进行测试。