简体   繁体   English

使用.htacces在Wordpress上用符号重定向网址

[英]Url redirect with symbols on Wordpress with .htacces

I've got a URL with something like this: 我有一个类似这样的URL:

www.google.com/?attachment_id=837

I want all the pages with an attachment to go to the homepage, for SEO reasons, I do not want those URLs to appear in a google search. 我希望所有带有附件的页面都转到主页,出于SEO的原因,我不希望这些URL出现在Google搜索中。 I try to delete with Yaogast plugin, but I think the theme that is on the page is not coded "right". 我尝试使用Yaogast插件删除,但是我认为页面上的主题未编码为“正确”。 I want to redirect to the home for example. 例如,我想重定向到家庭。

I tried something like this, and variations: 我尝试了类似的方法和变化:

redirect 301 /?attachment_id=837 http://google.com

RewriteRule ?attachment_id(.*) / [R=301, L]

I think that "?" 我觉得 ”?” and "=" in the URL is giving me some problems. 网址中的“ =“”给我一些问题。

The "?" “?” indicates a GET variable. 表示GET变量。 You cannot use URL Rewriting over GET variables. 您不能对GET变量使用URL重写。 Changing your .htaccess will not help. 更改.htaccess将无济于事。 I think the best thing to do here is to use the GET variable in the PHP file. 我认为最好的方法是在PHP文件中使用GET变量。 Access your PHP file from wordpress, and add this code in the beginning: 从wordpress访问您的PHP文件,并在开头添加以下代码:

if(isset($_GET['attachment_id'])) header('Location: redirect_url');

And replace "redirect_url" with the url you want to redirect to 并将“ redirect_url”替换为您要重定向到的URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM