Why is a link to www.example.software not working?

Why is a link to www.example.software not working? - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, https, no-www, www, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


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 ?


Solution :

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.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect