6

I have looked at some posts here, but they dont answer my problem. I have subdomains and addon-domains and not all of them have a certificate yet. So I cannot use a generic solution.

my .htaccess is

RewriteEngine On

#software
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.software$ [NC]
RewriteRule ^(.*)$ https://example.software%{REQUEST_URI} [R=301,L,QSA]


#force html extn
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

#For existing publishing
RewriteCond %{HTTP_HOST} ^example.software$ [NC]
RewriteRule ^(download)/([^/]+)$ https://example.software?mode=file&name=$2 [L]

With this, the following work

<a href="https://www.example.software">
<a href="http://www.example.software">
<a href="https://example.software">
<a href="http://example.software">

But this does not work

<a href="www.example.software">

It translates to

https://example.software/www.example.software

I tried adding this as second ruleset, its generic but still doesnt work

# remove www from https
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

I tried this and it has the same result

RewriteCond %{HTTP_HOST} ^www\.example\.software$ [NC]
RewriteRule ^(.*)$ https://example.software%{REQUEST_URI} [R=301,L,QSA]

Even with just this from another post here gives me the same result

RewriteCond %{HTTP_HOST} ^www.example.software$ [NC]
RewriteRule ^(.*)$ https://example.software$1 [R=301,L]

Is something else on my system causing it ?

0

1 Answer 1

17

A link like <a href="www.example.software"> is defined by the HTML/HTTP spec as a relative link.

  • If you are currently on https://www.example.software/ it would result in the URL https://www.example.software/www.example.software.
  • If you are currently on https://www.example.software/foo/some-page.html it would result in the URL https://www.example.software/foo/www.example.software

It is really no different than linking to other-page.html in terms of how browsers are supposed to interpret it.

When you link to your site, you should always include the protocol, or use relative links designed to link to the home page. The following links would lead to your home page:

  • <a href="https://www.example.software">
  • <a href="http://www.example.software">
  • <a href="//www.example.software"> -- A starting double slash is protocol relative linking where the protocol of the current page is used
  • <a href="/"> -- A single starting slash is "root relative linking" where the protocol and domain name from the current site are used.
  • <a href="./"> -- A starting dot slash is "document relative linking" where it links to the index of the current directory.

If you have linked incorrectly in the past and you want to redirect your malformed URLs to remove the host name in the directory path, you could use this rewrite rule:

RewriteRule ^/?((www\.)?example\.software(/.*)?)$ https://$1 [R=301,L]

That rule should take the domain name from the start of the URL path and redirect to make it the host name.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.