嗨,我正在尝试通过htaccess文件将旧网址重定向到新网址,但是我无法在文件中同时运行其他脚本
我尝试了其他重定向url的脚本,但仍然无法正常工作,我不知道可能是什么问题,但是我在想,也许是因为脚本的顺序不正确,所以有人可以帮我吗并预先感谢
AddType 'text/html; charset=UTF-8' html
RewriteEngine On
Redirect /old-domain.com https://new-domain.com
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://new-domain.com/$1 [L,R=301]
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>
答案 0 :(得分:0)
Redirect /old-domain.com https://new-domain.com
毫无意义,它试图重写不是您想要的文件夹“ old-domain.com”。我真的建议您仔细阅读所用工具的文档。它的质量非常好,并附带了很多示例...
相反,使用重写模块来研究这种方法:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$
RewriteRule ^/?(.*)$ https://new-domain.com/$1 [R=301]
一个好主意是从302临时重定向开始,然后在确定一切正确设置之后,才将其更改为301永久重定向。这样可以防止在尝试时缓存问题...
此实现将在http服务器主机配置或动态配置文件(“ .htaccess”文件)中同样起作用。显然,重写模块需要加载到http服务器内部并在http主机中启用。如果使用动态配置文件,则需要注意在主机配置中完全启用了它的解释,并且该解释位于主机的DOCUMENT_ROOT
文件夹中。
还有一个一般性说明:您应该始终喜欢将此类规则放置在http服务器主机配置中,而不要使用动态配置文件(“ .htaccess”)。这些动态配置文件增加了复杂性,通常是导致意外行为,难以调试的原因,并且确实降低了http服务器的速度。仅当您无法访问真正的http服务器主机配置(阅读:真正便宜的服务提供商)或坚持编写自己的规则的应用程序(这显然是安全的噩梦)时,才提供它们作为最后的选择。