我有一个似乎是正确配置的 .htaccess 文件,该文件将 http 重定向到 https ,并将301个已定义的URL重定向。< / p>
DirectoryIndex app.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# RedirectS //
Redirect 301 /content/166/b6seriespremiumbodyday/nightcamerairlightingwith49mmzoomlenssonyproelectronicspack.aspx https://www.example.co.uk/shop/cctv-cameras/day-night/b6-4-9mm-lens/
# .. loads more redirects here (left out for brevity)
Redirect 301 /content/93/bnc/ https://www.example.co.uk/shop/cctv-accessories/cctv-cable-accessories/bnc-to-scart-adapter-for-television-monitors
# // RedirectS
# DOMAIN
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk
RewriteCond %{HTTP_HOST} !^dev\.example\.co\.uk
RewriteCond %{HTTP_HOST} !^example\.local
RewriteCond %{HTTP_HOST} !^www\.example\.local
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]
# // DOMAIN
# HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^dev\.example\.co\.uk
RewriteCond %{HTTP_HOST} !^example\.local
RewriteCond %{HTTP_HOST} !^www\.example\.local
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# // HTTPS
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:Redirect_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
## EXPIRES CACHING ##
<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 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 week"
</IfModule>
## EXPIRES CACHING ##
当有人输入错误的地址或链接在网站上中断时,问题就出现了;例如, example.com/khdkhdkjh 在自定义404页面上结束但是在那里显示为 https://www.example.com/khdkhdkjh/ 。
你可能想不出什么大不了的事;然而,谷歌网站管理员工具显示这是一个错误的404&#34;因为重写了 advance 404。
如何构建htaccess以确保格式错误的网址之前 301重定向?