【发布时间】:2020-04-29 01:13:56
【问题描述】:
我已经做了 3 天了,没有任何结果!
我有一个现有的 http 站点,它有很多重定向规则,具体取决于 URL 友好链接,我现在需要强制加载到 https - Google 最终会将它们从索引中删除,但有很多来自第 3 方的页面链接我无法实际更改的网站。
下面的.htaccess 处理http://example.com,但显然不是http://www.example.com
问题是,如果我添加一个重写并让它专门将 url 前缀更改为 https,它要么根本不起作用,要么会转发到 https://www.example.com,但随后会给出一个错误消息,因为重定向太多(取决于我尝试过的 http 到 https 的版本)。
我还尝试将代码拆分为首先检查 https/redirect,然后检查非 www,但是当它正确转发时,它会再次创建循环或剥离原始查询。
帮助!哈哈
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule ^(.*)$ https://www.example.co.uk/$1 [R=301,L]
RewriteRule ^2/Home https://www.example.co.uk/ [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?docid=$1&docname=$2 [QSA,L]
RewriteRule ^item/([^/\.]+)/([^/\.]+)/?$ item.php?prodid=$1&prodname=$2 [QSA,L]
RewriteRule ^search/ store.php [QSA,L]
RewriteRule ^store/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ store.php?catid=$1&startPage=$2&limitPerPage=$3&searchTerm=$4 [QSA,L]
RewriteRule ^store/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ store.php?catid=$1&startPage=$2&limitPerPage=$3 [QSA,L]
RewriteRule ^store/([^/\.]+)/([^/\.]+)/?$ store.php?catid=$1&catname=$2 [QSA,L]
RewriteRule ^sitemap\.xml/?$ sitemap.php
ErrorDocument 404 /15/Error
AddType application/x-font-woff2 .woff2
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
#6 month for image files
<filesMatch ".(jpg|jpeg|png|gif|ico)$">
Header set Cache-Control "max-age=15552000, public"
</filesMatch>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
# 6 month for css and js
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=15552000, public"
</filesMatch>
# long expire
<filesMatch ".(woff2)$">
Header set Cache-Control "max-age=102628000, public"
</filesMatch>
<IfModule mod_deflate.c>
#Enable Gzip compression
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/eot
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/vnd.microsoft.icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs for legacy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting