首页 > 解决方案 > 301 .htaccess 重定向 apache 服务器

问题描述

所以我遇到了我想要所有请求的问题

https://transfinmedia.com/author?url=akchopra1-A268

被301重定向

https://transfinmedia.com/author/akchopra1-A268

但是当我使用

RewriteEngine on
RewriteCond %{QUERY_STRING} url=(.*) 
RewriteRule ^author(.*) /author/%1 [L,R=301,NC]

请求

https://transfinmedia.com/author?url=akchopra1-A268被重定向到

https://transfinmedia.com/author/akchopra1-A268?url=akchopra1-A268

我在这里做错了什么,完全不知道。

标签: regexapache.htaccessredirect

解决方案


默认情况下,mod-rewrite 将 old 附加QueryString到新的目标 url。要丢弃 QueryString ,您需要? 在目标 url 的末尾放置一个(空问号)。

RewriteEngine on
RewriteCond %{QUERY_STRING} url=(.*) 
RewriteRule ^author(.*) /author/%1? [L,R=301,NC]

确保在使用之前清除浏览器缓存。


推荐阅读