Cecil Ward
Cecil Ward

Reputation: 580

In an Apache .htaccess, can I rewrite an http: URL to https: and a non-www URL to www without an HTTP 301 redirect?

In my Apache 2 .htaccess file I would like to rewrite http: to https:, non-www to www., and myfile to myfile.htm all without http 301 redirects if possible.

I would also like the snippet of code to not mention the server name explicitly so that the code could be used in various servers’ .htaccess files without modification.

So http://example.com -> https://www.example.com and https://example.com -> https://www.example.com and https://www.example.com/myfile -> https://www.example.com/myfile.htm

Can anyone help me achieve this ultimate .htaccess rewriter?

Upvotes: 0

Views: 45

Answers (1)

Brummer
Brummer

Reputation: 31

Here is a small excerpt from link showing how to solve this task.

If you want to redirect a website from the non-www version to the www version with https, the entry would look like this:

RewriteEngine On
RewriteCond %{HTTP_HOST}^eineseite.de$
RewriteRule ^(.*)https://www.eineseite.de/$1[L,R=301]

I tried to roughly translate it for you. Also, I think you won’t achieve this type of redirect without using 301 to 307 redirects. You could program your own web server, but I guess that’s not realistic.

Upvotes: -1

Related Questions