重定向到带问号的错误 URL (Dreamhost)

Redirecting to wrong URL with Question Mark (Dreamhost)

假设:

Capital = https://www.emeraldbabe.com/profile/Prabhas/347
Small = https://www.emeraldbabe.com/profile/prabhas/347
Wrong = https://www.emeraldbabe.com/profile/prabhas/347?/profile/Prabhas/347

我想从 Capital 重定向到 Small

但是当我打开 Capital 它正在重定向到 Wrong URL.

下面是我的 Htaccess 代码

RewriteEngine on
RewriteCond  !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]


# Redirect URLs of the form "/index.php/<URL>" to "/<URL>"
# Also handles "/index.php" only
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index.php(?:/(.*))?$ / [R=301,L]

RewriteEngine on
ErrorDocument 404 https://www.emeraldbabe.com/
ErrorDocument 402 https://www.emeraldbabe.com/
ErrorDocument 501 https://www.emeraldbabe.com/
ErrorDocument 502 https://www.emeraldbabe.com/
ErrorDocument 401 https://www.emeraldbabe.com/

Redirect 301 /profile/Prabhas/347 /profile/prabhas/347

您的 mod_alias Redirect 指令与您的 front-controller 冲突(第一个使用 mod_rewrite 的规则)。 Redirect 始终处理请求的 URL-path,但它正在从重写的 URL.

中捕获查询字符串

您的规则顺序错误,您需要使用 mod_rewrite(即 RewriteRule)来避免此冲突。不同的 Apache 模块独立工作,不一定按照配置文件中指定的顺序工作。

旁白: 将所有错误响应重定向到主页通常对 SEO 和用户不利。

例如:

ErrorDocument 404 https://www.example.com/
ErrorDocument 402 https://www.example.com/
ErrorDocument 501 https://www.example.com/
ErrorDocument 502 https://www.example.com/
ErrorDocument 401 https://www.example.com/

RewriteEngine on

# Correct case of URL
RewriteRule ^profile/Prabhas/347$ /profile/prabhas/347 [R=301,L]

# Redirect URLs of the form "/index.php/<URL>" to "/<URL>"
# Also handles "/index.php" only
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index.php(?:/(.*))?$ / [R=301,L]

# Front-controller
RewriteCond  !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]