簡體   English   中英

htaccess 從 url 中刪除段並重定向到 https 和 www

[英]htaccess remove segment from url and redirect to https and www

我正在使用 Deployer 將 Craft CMS 站點部署到共享主機帳戶。

最新部署可從 domain.com/current/public 訪問

我的 .htaccess 文件如下所示,它從 url 中刪除當前/公共,並強制 https:

RewriteEngine on
RewriteRule ^(.*)$ current/public/$1
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

我現在還需要重定向所有網址以使用 www

如何調整我的 .htaccess 以在所有網址上強制使用 www?

*** 更新 ***

我設法通過以下方法解決了上述問題:

RewriteEngine on
RewriteRule ^(.*)$ current/public/$1
RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+) [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]

當我 go 到example.com/admin它重定向到example.com/current/public/admin 如何調整我的 htaccess 文件以從管理 url 中刪除“當前/公共”?

您的http->httpswww添加規則應該是最重要的規則,以便它適用於原始 URI,而不是由於其他規則而重寫的 URI。

RewriteEngine on

RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+) [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^(.*)$ current/public/$1 [L]

確保在測試此規則之前清除瀏覽器緩存。

還要在/current/public/.htaccess中添加此重定向規則:

RewriteCond %{THE_REQUEST} /current/public/(\S+) [NC]
RewriteRule ^ /%1 [R=301,L,NE]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM