我在.htaccess中使用了这个
RewriteCond %{HTTP_HOST} ^customlogoshop.com [NC]
RewriteRule ^(.*)$ http://www.customlogoshop.com/$1 [L,R=301]
但是,只有我的主页customlogoshop.com
被重定向到www.customlogoshop.com
。我的所有其他页面都不会重定向。
更新:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+)/$ /$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^customlogoshop.com [NC]
RewriteRule ^(.*)$ http://www.customlogoshop.com/$1 [L,R=301]
这些规则正在做的是将.php重定向到非扩展URL。尾随斜杠被重定向到非尾随斜杠网址。
答案 0 :(得分:0)
将重定向规则置于其他所有内容之上。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^customlogoshop.com [NC]
RewriteRule ^(.*)$ http://www.customlogoshop.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+)/$ /$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]