大网数据广告活动
网站运营与故障问答

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

· 52CE 我爱测

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 Rew…

问题原文

原帖链接 · Rohit Gupta · CC BY-SA 4.0

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 ?

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2022-01-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。