我的重定向的 htaccess RewriteRule 不起作用

The htaccess RewriteRule for my redirect is not working

我想重定向这个 URL:

www.example.com/index.php?id=16632

到这个URL:

www.example.com/downloads/patterns

我尝试在我的 typo3 安装的 .htaccess 文件中使用这个 RewriteRule:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=16632$
RewriteRule ^/index\.php$ /downloads/patterns [R=301,L]

但它不起作用。 RewriteRule 中的语法有什么问题吗?或者是否与其他规则冲突(这些规则已经在 typo3 的标准 htaccess 文件中):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=16632$
RewriteRule ^/index\.php$ /downloads/patterns [R=301,L]

RewriteCond [=11=]#%{REQUEST_URI} ([^#]*)#(.*)$
RewriteRule ^.*$ - [E=CWD:%2]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}. [L]


RewriteRule _(?:recycler|temp)_/ - [F]
RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]


RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule (?:^|/)\. - [F]

RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]

如果有人能帮助我,我将不胜感激。

谢谢!

您的规则无效,因为它在模式中有一个前导斜杠。如果您在 htaccess 中使用它,则不能在 RewriteRule 中使用前导斜杠。

这应该有效:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=16632$  
RewriteRule ^index\.php$ /downloads/patterns? [R=301,L]

重写目标末尾的空问号 ? 很重要,因为它会丢弃新位置的旧查询字符串。