Mod重写位置标头包含根文件路径

问题描述 投票:-1回答:1

我正在尝试重写

[https://example.com/vehicles.php?id=42https://example.com/vehicles/brand/honda

以处理我的新URL更改而不影响SEO。 (即“ 42”应映射到“本田”)

我尝试过this

RewriteCond  %{QUERY_STRING}  ^id=42$                   
RewriteRule  ^vehicles.php$  ^vehicles/brand/honda$    [L,R=301]   #to handle old URLs to new URL mapping
RewriteRule  ^vehicles/brand/honda$   ^vehicles.php?id=42$   [L]  #to handle URL to file mapping

但是它重定向到

https://example.com/root/site/%5evehicles/brand/honda$?id=42,有两种错误。

  1. 它包含文件路径(/root/site
  2. 我希望删除查询参数。

感谢您为解决此问题提供的帮助。

php .htaccess mod-rewrite query-string
1个回答
0
投票

行尾的字符?从输出路径中删除查询字符串。

RewriteCond %{QUERY_STRING} ^id=42$
RewriteRule  ^vehicles.php$  vehicles/brand/honda?    [L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.