dpl74687 2017-05-02 14:00
浏览 74
已采纳

apache htaccess不会将https:// www添加到除inside.php之外的任何页面

We have a client's site that is currently on our development server. We are having some issues formatting the .htaccess file. Currently, the htaccess file is causing a redirect to https://www. only on inside.php. Our goal is to make every page redirect to use https://www.. We are currently using a base url set-up in our header.php file that is included on every page. Unsure if there is a better way to accomplish what we are trying to do, but if there is any help would be appreciated.

Here is the current contents of our .htaccess file.

RewriteEngine on

#enables you to access PHP files with HTML extension
AddType application/x-httpd-ea-php70 .html .htm

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

#forces https://
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#forces www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


RewriteRule ^physicians(/((([a-zA-Z0-9_-]+)/?)*))?$    physicians.php?link=$2    [NC,L]

RewriteRule ^((([a-zA-Z0-9_-]+)/?)*)$ inside.php?page=$1


ErrorDocument 404 /inside.php
  • 写回答

1条回答 默认 最新

  • dongqiongzheng0615 2017-05-02 14:28
    关注

    You exit early, when the request is for a real file, directory or symbolic link

    RewriteRule ^ - [L]
    

    Only after this rule, requests are redirected to https://www.. To redirect all requests to https://www., move the rules to the beginning, e.g.

    #forces www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
    
    #forces https://
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
    
    # all other rules come here
    # ...
    

    I also moved the non-www part to the front, because otherwise you have two redirects, if the original request is for http://example.com.

    Never test with R=301!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致