当我正在开发的网站的安全部分(使用https输入特定页面或文件夹)时,与普通页面的相对链接也会自动转换为https.
有没有办法告诉<a>标签始终使用http协议而不是https协议(或其他方式)?
我知道使用完整链接(http://www.mysite.com/index.html或https://www.mysite.com/index.html)很容易,但我希望它可以使用相关链接(index.html,../index.html等).
Mat*_*hew 29
您可以使用以下语法使所有内部链接独立于协议:
<a href="//some/file/on/your/domain.php">link text</a>
代替
<a href="some/file/on/your/domain.php">link text</a>
这//将使链接尊重页面加载的任何协议.
小智 10
我们使用Apache mod_rewrite来控制页面是通过http还是https提供的.以下是网站根目录.htaccess文件中的示例代码段:
# Redirect most reqests for https to http
RewriteRule ^https://www.example.com(.*) http://www.example.com$1 [R=301,NC]
# Allow some URIs to be https if requested
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/images/(.*)$
RewriteCond %{REQUEST_URI} !^/scripts/(.*)$
RewriteCond %{REQUEST_URI} !^/styles/(.*)$
RewriteCond %{REQUEST_URI} !^/store(.*)$
RewriteCond %{REQUEST_URI} !^/login.htm$
RewriteRule ^(.*) http://www.example.com/$1 [L,R]
# Force some URIs to be https only
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^store(.*) https://www.example.com/store$1 [L,R]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^FormSanityKey.htm https://www.example.com/login$1 [L,R]
Run Code Online (Sandbox Code Playgroud)
阅读所有相关信息:
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
| 归档时间: |
|
| 查看次数: |
51405 次 |
| 最近记录: |