带有两个参数的 .htaccess 重定向到 404 页面
.htaccess with two parameters redirects to a 404 page
我想将 /index.php?id=1&time=10
重定向到 /first-10
。
.htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} id=1&time=10
RewriteRule ^index\.php$ /first-10/? [L,R=301]
当我访问 /index.php?id=1&time=10
时重定向到 /first-10/
,但这是一个 404 页面。请注意最后一个斜杠。
问题出在哪里?
您需要在内部将其重写回原来的格式。
您必须使用 THE_REQUEST
以避免无限循环
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/(?:index\.php)?\?id=1&time=10\s [NC]
RewriteRule ^ /first-10? [R=301,L]
RewriteRule ^first-10$ /index.php?id=1&time=10 [L]
http://example.com/index.php?id=1&time=10
和 http://example.com/?id=1&time=10
都将重定向到 http://example.com/first-10
。
http://example.com/first-10
将在内部将其重写回 /index.php?id=1&time=10
如果问题确实出在 .htaccess 上,那么结果页面是正确的并且调用了重定向,我想:
“?” character betwhen first-10/ and [L,R= ???
或者 first-10 之后的 / ???
我想将 /index.php?id=1&time=10
重定向到 /first-10
。
.htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} id=1&time=10
RewriteRule ^index\.php$ /first-10/? [L,R=301]
当我访问 /index.php?id=1&time=10
时重定向到 /first-10/
,但这是一个 404 页面。请注意最后一个斜杠。
问题出在哪里?
您需要在内部将其重写回原来的格式。
您必须使用 THE_REQUEST
以避免无限循环
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/(?:index\.php)?\?id=1&time=10\s [NC]
RewriteRule ^ /first-10? [R=301,L]
RewriteRule ^first-10$ /index.php?id=1&time=10 [L]
http://example.com/index.php?id=1&time=10
和http://example.com/?id=1&time=10
都将重定向到http://example.com/first-10
。http://example.com/first-10
将在内部将其重写回/index.php?id=1&time=10
如果问题确实出在 .htaccess 上,那么结果页面是正确的并且调用了重定向,我想:
“?” character betwhen first-10/ and [L,R= ??? 或者 first-10 之后的 / ???