0
votes

I have the following problem. I want multiple htaccess rewriterules to result in only one 301 redirect.

URL: http://examle.com/Foo

Target URL: https://www.example.com/bar

My current situation is the following redirect chain:

http://example.com/Foo

301 -> https://www.example.com/Foo

301 -> https://www.example.com/foo

301 -> https://www.example.com/bar

# Rewrite unsecure connections to https connections
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L,NC,NE]

# Rewrite connections without subdomain to www subdomain
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L,NC,NE]

# Enforce lowercase on urls
RewriteCond %{REQUEST_URI} [A-Z]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:REWRITEBASE}${lc:$1} [L,R=301]


RewriteRule ^foo$ %{ENV:REWRITEBASE}bar [L,R=301,QSA]

What do I need to change?

1

1 Answers

0
votes

Please try this:

  1. comment your last rule # RewriteRule ^foo$ %{ENV:REWRITEBASE}bar [L,R=301,QSA]

  2. before comment # Rewrite unsecure connections to https connections add rule:

    RewriteRule ^Foo$ https://www.example.com/bar [NC,L,R=301,QSA]

    or check rule

    RewriteRule ^(foo|Foo)$ https://www.example.com/bar [L,R=301,QSA]