用URL中的.htaccess替换字符串

时间:2018-10-31 20:06:06

标签: apache .htaccess

我需要编辑.htaccess文件,以便该字符串:

  

https://example.com/haathumb.php?var=400x300/src/wp-content/uploads/2017/08/brain-training-game-show-app-improves-memory.jpg

已被替换为以下字符串:

  

https://example.com/thumb/400x300/src/wp-content/uploads/2017/08/brain-training-game-show-app-improves-memory.jpg

总而言之,我需要使用haathumb.php?var=在字符串中将thumb替换为.htaccess。我该怎么办?

2 个答案:

答案 0 :(得分:1)

从haathumb.php?var = ...重定向到thumb / ...然后?

RewriteEngine on

RewriteCond %{QUERY_STRING} (?:^|&)var=([^&]+)
RewriteRule ^haathumb\.php$ /thumb/%1? [L,R=permanent]

答案 1 :(得分:0)

我最终使用下面的.htaccess代码使haathumb正常工作:

# BEGIN haathumb rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^thumb/(.*) /haathumb.php?var=$1 [L]
</IfModule>
# END haathumb rewrite