简体   繁体   中英

Url redirect with symbols on Wordpress with .htacces

I've got a URL with something like this:

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. I try to delete with Yaogast plugin, but I think the theme that is on the page is not coded "right". 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. You cannot use URL Rewriting over GET variables. Changing your .htaccess will not help. I think the best thing to do here is to use the GET variable in the PHP file. Access your PHP file from wordpress, and add this code in the beginning:

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

And replace "redirect_url" with the url you want to redirect to

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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