【问题标题】:How to change url path and have https:// instad of http?如何更改 url 路径并使用 https:// 而不是 http?
【发布时间】:2017-02-17 22:56:08
【问题描述】:

我正在尝试更改我的 url 路径:

example.com/path/index.php

http://example.com/path/index.php

https://example.com/

-

www.example.com/path/index.php

http://www.example.com/path/index.php

https://www.example.com/path/index.php

这是我目前所拥有的,它适用于 https:// 部分,但不适用于更改我的 url 路径

.htaccess 文件

#First rewrite any request to the wrong domain to use the correct one (here www.)

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

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


#Change to / instead of /path/index.php (Doesn't work.)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ path/index.php?/$1 [L]

【问题讨论】:

    标签: .htaccess url https url-rewriting


    【解决方案1】:

    我还不能评论,所以我在这里问:

    您的问题/要求最终将在 2 个带有 www 的域和不带 www 的域中提供请求:

    example.com/path/index.php
    

    http://example.com/path/index.php
    

    https://example.com/
    

    返回到着陆页 --- 没有重定向到 www.example.com,对吗?

    www.example.com/path/index.php
    

    http://www.example.com/path/index.php
    

    https://www.example.com/path/index.php
    

    只是强制启用https?

    如果是真的,那么你的代码如下

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

    正在向主机添加 www,与您发布的要求/问题无关。你能把你的问题说得更清楚吗?

    【讨论】:

    • 对此我深表歉意,是的。我这样做是为了将所有内容重定向到 www。我粘贴了错误的代码(www.版本),这并不重要。我的主要观点是强制 https 并更改 url 路径/装载页面。
    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 2013-09-19
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多