Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache htaccess301重定向_Apache_.htaccess_Http Status Code 301_Opencart - Fatal编程技术网

Apache htaccess301重定向

Apache htaccess301重定向,apache,.htaccess,http-status-code-301,opencart,Apache,.htaccess,Http Status Code 301,Opencart,如何使用301重定向将www.添加到域 .htaccess内容: #Options +FollowSymlinks <IfModule mod_rewrite.c> RewriteEngine On #OPENCART REWRITES START RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php #OPENCART REWRITE

如何使用301重定向将
www.
添加到域

.htaccess
内容:

#Options +FollowSymlinks

<IfModule mod_rewrite.c>
RewriteEngine On

#OPENCART REWRITES START
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
#OPENCART REWRITES END

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www\.mysite\.com/$1 [R=301,L]
</IfModule>
#选项+FollowSymlinks
重新启动发动机
#OPENCART重写开始
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)index.php
#OPENCART重写结束
重新启动发动机
重写基/
重写cond%{HTTP_HOST}^www\.mysite\.com$[NC]
重写规则^(.*)$http://www\.mysite\.com/$1[R=301,L]

请注意,302重定向正在工作

我认为您只需要在Apache配置文件中执行此操作

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] 
我是这样使用的:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.net
RewriteRule ^(.*)$ http://www.mysite.net/$1 [R=permanent,L]

试试这个代码。我将此作为非www到www和强制https的标准。无需进一步更改

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,NE]

你确定是302而不是301?运行了.htaccess,301也能正常工作,不幸的是,我敢肯定。您可以显示日志中显示它运行302的部分吗?在StackOverflow上看到这个答案: