现在我有了这段代码
RewriteEngine On
RewriteBase /
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
# remove index and reference the directory
RewriteRule (.*)/index$ $1/ [R=301]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.html [L]
#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]
它的工作非常好,但它将我们的cdn图像从cdn.domain.com/img.jpg重定向到www.domain.com/img.jpg我该如何防止这种情况发生?
答案 0 :(得分:0)
您可以通过在规则前加上cdn.
和无替换
RewriteCond %{HTTP_HOST} ^cdn\.
RewriteRule ^ - [L]
此规则会将网址保留为-
- (破折号)
短划线表示不应执行替换 (现有路径不受影响)。这是用的 当需要应用标志(见下文)而不改变时 路径。
并停止进一步重写L|last
[L]标志使mod_rewrite停止处理规则集。