0

I want to be able to have the an URL be reformed in an htaccess file and redirect a file that is no longer present.

Taking this:

http://www.example.com/foo/thing.htm

and having this be renamed to:

https://example.com/foo/

I've used the following code

RewriteEngine On

Redirect 301 /foo/thing.htm /foo/

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
    
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI}

The problem I have had is that when the Redirect 301 happens, the RewriteCond is skipped according to https://htaccess.madewithlove.com/

Redirect 301 /foo/thing.htm /foo/

The new url is http://www.example.com/foo/

Test are stopped, a redirect will be made with status code 301

and the output is http://www.example.com/foo/

How can I get all of my commands in my htaccess file be ran so that the URL is processed properly in addition to any other additional commands such as cache control and webp compatability?

4
  • Shouldn't http://www.example.com/foo/ then redirect to HTTPS? It isn't usually a problem to have a short chain of redirects. Sep 18 at 6:11
  • Yes. That's what I need help with. The output is incorrect in my htaccess Sep 18 at 21:39
  • Have you tried using rewrite rules for everything rather than a redirect? Sep 18 at 21:53
  • No I haven't. That's not a bad idea. I have just been using scripts that I've found online, tbh. Sep 18 at 22:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.