URL 通过 .htaccess 规范化
URL Canonicalization through .htaccess
我正在尝试将 http://www.example.me
重定向到 http://example.me
,但由于某种原因它不起作用。有人可以告诉我 .htaccess
文件有什么问题吗?
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/“ [R=301,L]
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
试试这个并且不要在你的规则中使用引号
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^ http:\example.me [R=301,L]
引号有问题。下面是正确的.htaccess
最后一个引号出现在这一行
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]
您可以在下面检查完整正确的 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
我正在尝试将 http://www.example.me
重定向到 http://example.me
,但由于某种原因它不起作用。有人可以告诉我 .htaccess
文件有什么问题吗?
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/“ [R=301,L]
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
试试这个并且不要在你的规则中使用引号
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^ http:\example.me [R=301,L]
引号有问题。下面是正确的.htaccess
最后一个引号出现在这一行
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]
您可以在下面检查完整正确的 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>