0

I know, such a question has been asked and answered multiple times in the past before. However, as I tried out all the solutions I found online, it didn't solve my problem. The issue is that I have a wordpress site, which, when someone googles the address, google gives some results of pages are empty. The site in question is garrymbsmith.com and the unwanted results are for example http://www.garrymbsmith.com/?nava=contact http://www.garrymbsmith.com/?nava=home-2

These results unfortunately don't give a 404 error page as it would be easy then to just modify the 404.php file and redirect people straight to the home page. They seem like normal pages but they are not. They are empty and the main navigation bar on top also doesn't help people go to the home page (the site is a single page website and the menu links are actually targeting anchor links within the same home page).

As I said, editing the 404.php didn't help as they are not such kind of pages. I searched super thorougly within the admin area for unwanted pages, posts, tags, categories, galleries etc... but without any luck... I can't find anything that justifies the existence of these links.

So, I hope that someone can help me with this as it is driving me crazy. I believe that with htaccess I could force these 3 links to redirect to the home page... Help please!!! Many thanks in advance

Zisis

  • 1. If you don't like google result point to X page on your site then use the webmaster tools. 2. You theme sucks if it can not properly do the redirects by itself. There is no real way to even start helping you without seeing its code. – Mark Kaplun Sep 11 '15 at 6:57
0

If you're going to have plenty of URLs to be handled later on, you can use Simple 301 Redirects (or similar) plugin available on WP Repo.

Here is the link: https://wordpress.org/plugins/simple-301-redirects/

The plugin offers options on WP dashboard instead of playing with htaccess file.

I'm finding it very helpful with Woocommerce site where, sometimes I have to deal with many URLs.

  • As I was trying to avoid using a plugin, I prefered an htaccess solution but... what the heck... your suggestion saved me. I wonder why I didn't think of searching for a plugin myself. Thanks very much!!! – Zisis Paparidis Sep 11 '15 at 18:31
  • You're most welcome ;) – tushonline Sep 11 '15 at 18:33
1

You need to Rewrite and redirect URLs with query parameters

For example:

This URL: garrymbsmith.com/?nava=contact

To destination URL: www.garrymbsmith.com

.htaccess syntax:

RewriteEngine on
RewriteCond %{QUERY_STRING} nava=contact
RewriteRule ^index\.php$ /? [L,R=301]

For detailed reference of different htaccess rules/scenarios you may refer to this awesome resource: https://gist.github.com/ScottPhillips/1721489

Update Added After Comment

Please try this htaccess I took your htaccess code and modified it, let me know if it works?

<IfModule mod_rewrite.c> 
 RewriteEngine On 
 RewriteCond %{QUERY_STRING} nava=contact
 RewriteRule .*$ /? [L,R=301]
 RewriteBase / 
 RewriteRule ^index\.php$ - [L] 
 RewriteCond %{REQUEST_FILENAME} !-f 
 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteRule . /index.php [L]
</IfModule>
  • Ok, so my htaccess file now is like that: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} nava=contact RewriteRule ^index\.php$ /? [L,R=301] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> But it still leads me to the empty page... not the homepage... Did I use any incorrect syntax? – Zisis Paparidis Sep 11 '15 at 13:57
  • Hi sorry for late response, I have updated the syntax little .. i.e. instead of RewriteRule ^index\.php$ /? [L,R=301] , I have put it like RewriteRule .*$ /? [L,R=301] , let me know if this solves the issue? – Mohsin Sep 15 '15 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.