htaccess重定向301保留ID

时间:2019-10-17 18:51:37

标签: .htaccess

我想重定向永久301:

https://www.toto.com/index.php?id=4

https://www.toto.com/?id=4

这可以吗? =>

RewriteRule index.php?id=([0-9]+)$ /?id=$1 [L,NC,R=301]

谢谢!

1 个答案:

答案 0 :(得分:1)

您无法匹配查询字符串,即?及其后的RewriteRule中的一部分。

您可以使用以下规则从所有路径中删除index.php,但保留查询字符串:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]