Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Wordpress htaccess重定向到错误的URL_Wordpress_.htaccess_Url Redirection - Fatal编程技术网

Wordpress htaccess重定向到错误的URL

Wordpress htaccess重定向到错误的URL,wordpress,.htaccess,url-redirection,Wordpress,.htaccess,Url Redirection,我已在.htaccess中设置了以下规则: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / // Redirect old blog URLs to new location RewriteCond %{HTTP_HOST} ^www.objectsanduse.com/blog/$ RewriteRule ^(.*)$ http://www.objectsanduse.com/

我已在
.htaccess
中设置了以下规则:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    // Redirect old blog URLs to new location
    RewriteCond %{HTTP_HOST} ^www.objectsanduse.com/blog/$
    RewriteRule ^(.*)$ http://www.objectsanduse.com/$1 [R=301,L]

    // Wordpress rewrite rules
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

重新启动发动机
重写基/
//将旧博客URL重定向到新位置
重写cond%{HTTP_HOST}^www.objectsanduse.com/blog/$
重写规则^(.*)$http://www.objectsanduse.com/$1[R=301,L]
//Wordpress重写规则
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
URL
http://www.somedomain.com/blog/2016/01/19/some-post/
正确重定向到
http://www.somedomain.com/2016/01/19/some-post/


但是
http://www.somedomain.com/blog
重定向到
http://www.somedomain.com//2015/03/30/some-other-post

如果我理解正确,您只需要一条规则:

RewriteRule ^(blog\/?)(.*) http://%{HTTP_HOST}/$2 [R=301,L]
此规则接受任何以
blog
开头的旧URI(可选后跟
/

并捕获接下来的所有内容(其中所有内容都包括“一无所有”)


然后它重写URI,其中包含第二个捕获组,但没有前面的
blog/

,如果我理解正确,您只需要一个规则:

RewriteRule ^(blog\/?)(.*) http://%{HTTP_HOST}/$2 [R=301,L]
此规则接受任何以
blog
开头的旧URI(可选后跟
/

并捕获接下来的所有内容(其中所有内容都包括“一无所有”)


然后它重写URI,其中包含第二个捕获组,但没有前面的
blog/

您在该规则中遇到问题:

// Redirect old blog URLs to new location
RewriteCond %{HTTP_HOST} ^www.objectsanduse.com/blog/$
RewriteRule ^(.*)$ http://www.objectsanduse.com/$1 [R=301,L]
As
%{HTTP\u HOST}
变量只匹配域名,而不匹配
URI
。您可以通过播放以下内容来修复该规则:

// Redirect old blog URLs to new location
RewriteCond %{HTTP_HOST} ^www\.objectsanduse\.com$
RewriteRule ^blog(/.*)?$ http://%{HTTP_HOST}$1 [NC,R=301,L]

您在此规则中遇到问题:

// Redirect old blog URLs to new location
RewriteCond %{HTTP_HOST} ^www.objectsanduse.com/blog/$
RewriteRule ^(.*)$ http://www.objectsanduse.com/$1 [R=301,L]
As
%{HTTP\u HOST}
变量只匹配域名,而不匹配
URI
。您可以通过播放以下内容来修复该规则:

// Redirect old blog URLs to new location
RewriteCond %{HTTP_HOST} ^www\.objectsanduse\.com$
RewriteRule ^blog(/.*)?$ http://%{HTTP_HOST}$1 [NC,R=301,L]

这看起来和@anubhavaI一样,我稍微调整了一下。它现在应该可以很好地工作了。它看起来和@anubhavaI一样,我们稍微调整了一下。它现在应该可以很好地工作了。看起来已经尝试过了——即使是在匿名模式下尝试过,我仍然有同样的问题。你应该在Chrome开发工具中测试,并禁用缓存。然后在“网络”选项卡中查看301/302重定向URL的内容。我上一次编辑是在4小时前。顺便说一句,您接受的答案也与
/blog123
相匹配,似乎已经尝试过了-即使在匿名模式下尝试过,我仍然有同样的问题。您应该在Chrome开发工具中测试,并禁用缓存。然后在“网络”选项卡中查看301/302重定向URL的内容。我上一次编辑是在4小时前。顺便说一句,您接受的答案也与
/blog123