Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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 301重定向到什么地方?及。asp_Wordpress_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Wordpress 301重定向到什么地方?及。asp

Wordpress 301重定向到什么地方?及。asp,wordpress,.htaccess,mod-rewrite,redirect,Wordpress,.htaccess,Mod Rewrite,Redirect,我知道有几篇文章是关于这方面的,但我是一个新手,当谈到重定向在.htaccess文件,所以原谅我的无知!我尝试了一些方法,但我无法让它起作用 我有一个旧的url,我正试图将其重定向到.htaccess中。第一个/旧的url通过二维码包含在印刷品中,所以我有点卡住了。我尝试过使用简单的重定向301,但没有成功。我看过一些关于使用RewriteRule的帖子,但我在.htaccess(WordPress)中有现有的代码,我害怕修改,以防它破坏网站 # BEGIN WordPress <IfMo

我知道有几篇文章是关于这方面的,但我是一个新手,当谈到重定向在.htaccess文件,所以原谅我的无知!我尝试了一些方法,但我无法让它起作用

我有一个旧的url,我正试图将其重定向到.htaccess中。第一个/旧的url通过二维码包含在印刷品中,所以我有点卡住了。我尝试过使用简单的重定向301,但没有成功。我看过一些关于使用RewriteRule的帖子,但我在.htaccess(WordPress)中有现有的代码,我害怕修改,以防它破坏网站

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
有人有什么想法吗?谢谢您的时间。

此重写规则应重定向到

  • RewriteCond指令检查查询字符串参数
  • 如果您在
    /ourlocations.asp
  • RewriteRule的替换部分中的尾部
    会去除所有查询参数(如果希望传递参数,请将其删除)
  • [R=301]
    告诉Apache执行301重定向
-


重新启动发动机
重写基/
重写规则^index\.php$-[L]
RewriteCond%{QUERY_STRING}cat=41
RewriteCond%{QUERY_STRING}id=41
重写规则^ourlocations\.asphttp://domain.com/locations? [R=301]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

感谢您的帮助,最后我们找到了一个解决方案:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^ourlocations\.asp http://domain.com/locations? [L,R=301]

RewriteRule ^index\.php$ - [L]

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

</IfModule>

重新启动发动机
重写基/
重写规则^ourlocations\.asphttp://domain.com/locations? [L,R=301]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

另一种解决方案:

#结束WordPress
之后添加:

RedirectMatch 301 /index.asp(.*) http://www.domain.com/$1
例如:

www.domain.com/index.asp/string=test&url=22
将重定向到:

www.domain.com/string=test
现在需要在它后面写301,如下所示:

RewriteCond %{QUERY_STRING} ^string=test&url=22$
RewriteRule ^$ http://www.domain.com/requiredPage/? [R=301,L]

现在网址:
www.domain.com/index.asp/string=test&url=22
将301转到
www.domain.com/requiredPage/

谢谢@kjetilh的回复。不幸的是,我试了一下,结果还是不行。我尝试了几个不同的选项来添加它,在它的内部,在它的外部,添加重写引擎,但都不起作用。这是服务器设置问题吗?@mickmaster对不起,brainlag,我看到你在用WordPress。在WordPress中包含自定义.htaccess指令有点棘手,因为它会自动在.htaccess文件中生成(并重写)指令。稍后我会再讨论这个问题,否则您可以搜索类似“WordPress custom.htaccess重写规则”的内容,看看您找到了什么感谢您的时间。我会研究一下你的建议,看看会有什么结果。再次感谢。这是最好的答案。您应该能够为每个可能的查询参数重定向到特定的URL。
RewriteCond %{QUERY_STRING} ^string=test&url=22$
RewriteRule ^$ http://www.domain.com/requiredPage/? [R=301,L]