Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
Php 如何在wordpress中使用htaccess将非www重定向到www_Php_Xml_Wordpress_.htaccess_Redirect - Fatal编程技术网

Php 如何在wordpress中使用htaccess将非www重定向到www

Php 如何在wordpress中使用htaccess将非www重定向到www,php,xml,wordpress,.htaccess,redirect,Php,Xml,Wordpress,.htaccess,Redirect,我想将此url和重定向到和 此外,我也重定向到,但我的网站地图和机器人在两个网址(非www)和(www)打开,所以我只希望它只在www格式打开 我试着使用下面的代码 RewriteRule sitemap\.xml http://example.com/sitemap. [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] 及 但是对我不

我想将此url和重定向到和

此外,我也重定向到,但我的网站地图和机器人在两个网址(非www)和(www)打开,所以我只希望它只在www格式打开

我试着使用下面的代码

RewriteRule sitemap\.xml  http://example.com/sitemap. [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]


但是对我不起作用,请帮助我解决此问题。

您的第一个重定向规则是错误的。使用以下命令:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(sitemap\.xml|robots\.txt)$  http://www.%{HTTP_HOST}/$1 [L,R=301,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(sitemap\.xml|robots\.txt)$  http://www.%{HTTP_HOST}/$1 [L,R=301,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]