简体   繁体   English

URL将旧URL重写为新URL

[英]URL Rewrite old URL to new URL

I'm trying to rewrite this: 我正在尝试重写这个:

index.php?action=dlattach;topic=2745.0;attach=14374;image

to this: 对此:

attachments/opening-inauguracion-png.14374/

What I've built so far but it isn't working is this: 到目前为止我已经建立但它不起作用是这样的:

RewriteRule ^index\.php?=dlattach;topic=([0-9]+);attach=([0-9]+);image /attachments/$2/ [R=301,L]

To manipulate the query string you need to use a rewrite condition with %{QUERY_STRING} : 要操作查询字符串,您需要使用%{QUERY_STRING}的重写条件:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} attach=([0-9]+) [NC]
# if you need a more exact match of your current query string
# comment the above RewriteCond and uncomment the below RewriteCond
#RewriteCond %{QUERY_STRING} ^action=dlattach;topic=[0-9\.]+;attach=([0-9]+);image$ [NC]
RewriteRule ^index.php$ attachments/opening-inauguracion-png.%1/ [R=302,NC,L]

Also only change it to 301 once you have confirmed the rule is working to avoid caching your browser while testing a rule which can be bad in case the rule is not properly working to mitigate the same. 一旦确认规则正在努力避免缓存浏览器,同时测试规则可能会很糟糕,以防规则不能正常工作以缓解相同规则,也只需将其更改为301。

I think you mean the opposite: 我认为你的意思恰恰相反:

RewriteEngine On
RewriteRule ^attachments/opening-inauguracion-png.([0-9]+)$ /index.php?action=dlattach;topic=2745.0;attach=$1;image [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM