1

我正在使用 Apache Web 服务器(用于.htaccess处理 URL 重写)。

主域(例如example.com)由 WordPress 生成的 URL 重写管理。URL 重写适用于整个域,包括子域。

我有一个名为 的新子域http://static.example.com,它将一个 URL 转发到另一个外部 URL,例如转发到http://www.google.com. 那是 :

http://static.example.com/style.css将转发到http://www.google.com/css/some_path/style.css

但是,URL 重写会阻止它,并报告找不到文件,因为它/css/style.css在本地服务器中找不到。我的问题是:如何禁用子域的 URL 重写?

电流.htaccess如下:

RewriteEngine on

AddType application/rss+xml rss
AddType application/x-java-jnlp-file jnlp
Options All -Indexes

RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^/?$ "http\:\/\/example\.com" [R=301,L]

# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
        AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml
    </IfModule>
</IfModule>
<FilesMatch "\.(css|htc|js|js2|js3|js4|CSS|HTC|JS|JS2|JS3|JS4)$">
    <IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.11"
    </IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$">
    <IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.11"
    </IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|JSON|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
    <IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.11"
    </IfModule>
</FilesMatch>
# END W3TC Browser Cache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

RewriteCond %{HTTP_HOST} ^static\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.static\.example\.com$
RewriteRule ^/?$ "https\:\/\/google\.com\/css\/some_path\/" [R=301,L]

注意:注意转发实际上是包含在上面的。

ps 所有网址都是假的。

4

1 回答 1

1

代替

RewriteCond %{HTTP_HOST} ^static\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.static\.example\.com$
RewriteRule ^/?$ "https\:\/\/google\.com\/css\/some_path\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?static\.example\.com$
RewriteRule ^(.*)$ https://google.com/css/some_path/$1 [R=301,L]

整个htaccess将是:(调整)

RewriteEngine on

AddType application/rss+xml rss
AddType application/x-java-jnlp-file jnlp
Options All -Indexes


# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
        AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml
    </IfModule>
</IfModule>
<FilesMatch "\.(css|htc|js|js2|js3|js4|CSS|HTC|JS|JS2|JS3|JS4)$">
    <IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.11"
    </IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$">
    <IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.11"
    </IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|JSON|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
    <IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.11"
    </IfModule>
</FilesMatch>
# END W3TC Browser Cache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# redirect www.example.com/some to example.com/some
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?static\.example\.com$
RewriteRule ^(.*)$ https://google.com/css/some_path/$1 [R=301,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


</IfModule>
于 2013-06-09T10:38:00.487 回答