Welcome to WebmasterWorld Guest from 54.144.36.228

Forum Moderators: Ocean10000 & incrediBILL & phranque

How to rewrite url with question marks?

     
10:38 pm on May 1, 2017 (gmt 0)

New User

joined:July 20, 2015
posts: 36
votes: 0


Hi,

For a reason that i don't know google index some pages from our WP site.

https://example.com/press/?post_type=projects&p=2177
https://example.com/?tag=61
etc

Question = How can i redirect/rewrite this pages to

e.g.
https://example.com/page/


thanks


[edited by: not2easy at 10:47 pm (utc) on May 1, 2017]
[edit reason] example/readability [/edit]

1:08 am on May 2, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10887
votes: 72


what have you tried and what mod_rewrite directives are already in place?
1:44 am on May 2, 2017 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3324
votes: 162


This is common in Wordpress because Wordpress offers several ways to find the same content. Most people deal with it by indexing only one form of an URL and using canonical for /tag/, /archive/ and /category/ URLs. The same content is available at all those URLs so you should choose the format you prefer to index and submit only those URLs on your sitemaps. There are plugins that do that according to the choices you make.
1:19 am on May 3, 2017 (gmt 0)

New User

joined:July 20, 2015
posts: 36
votes: 0


I tried

RewriteCond %{QUERY_STRING} page_id=99
RewriteRule ^(.*)$ http://www.example.com/page/ [R=301,L]

it doesn't work

What i need all links like this ?page_id=99 (?page_id=98 or ?page_id=1) to be redirected to /page/

[edited by: not2easy at 2:29 am (utc) on May 3, 2017]
[edit reason] please use example.com for readability [/edit]

2:51 am on May 3, 2017 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3324
votes: 162


You can change the structure [codex.wordpress.org] of your URLs (Permalinks) in the Admin Interface. Go to Settings, then click on Permalink Settings and choose how you want your URLs to look.
4:56 am on May 3, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13825
votes: 484


What i need all links like this ?page_id=99 (?page_id=98 or ?page_id=1) to be redirected to /page/

That's very straightforward-- but it's even easier to let WP do it for you.

Another thing you ought to be doing, if you haven't already, is to go into the Parameters area of GSC (the former WMT) and take a close look at your settings. There's an array of options, like "pick some value at random" or "ignore this parameter" or even "don't crawl URLs with this parameter at all".
3:35 pm on May 3, 2017 (gmt 0)

New User

joined:July 20, 2015
posts: 36
votes: 0


Not2Easy,
With Permalink settings everything is ok on website. All our urls are like domain_com/page-name/. The issue is comming from GSC where i found a lot of 404 errors with just urls like ?page_id=98 or ?page_id=1 which we don't have (usually in GSC you can see from where it linked, but for this URLs there isn't and page mentioned). I can leave this URLs to get 404 error, but i guess for SEO it will be better to redirect it to excising page. I have feeling that having 404 error pages isn't good signal for SEO. That's the reason why i need to "fix" this urls

?tag=316
?page_id=83

thanks
4:00 pm on May 3, 2017 (gmt 0)

New User

joined:July 20, 2015
posts: 36
votes: 0


Lucy 24,

Thanks for this advice. To be honest i don't know that GSC have such section. So for example if i don't need google to crawl ?tag pages i need to switch to "No: Doesn't affect page content (ex: tracks usage)" drop down menu ?

correct me if i'm wrong
4:12 pm on May 3, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13825
votes: 484


Edit: We were typing at the same time, so this is in response to the second-to-last post.

There is absolutely nothing wrong with a 404. Not everything listed as an "error" in GSC is an actual mistake that you have to fix; it's just for your information. In fact, if the Googlebot meets a lot of redirects, it will intentionally ask for a garbage URL like krdifghkjkjhu.html just to make sure the request gets a 404 rather than a 301. They may be doing something similar on your site, only with parameters instead of URL paths: they want to be certain that not all conceivable parameter values return a 200. So the 404 is good and may be exactly what they're looking for.

The one time a 404 is problematic is if Google learned about the nonexistent URL from a link on your own site. This doesn't seem to be the case here.

Do take a look at the Parameters area of GSC (it's under Crawl, not under Index) and make sure you agree with how everything is getting handled. Most of the time they guess right, but obviously you know your site better than they do.
5:31 pm on May 3, 2017 (gmt 0)

New User

joined:July 20, 2015
posts: 36
votes: 0


Lusy,

As i told in my previous post - "I have feeling that having 404 error pages isn't good signal for SEO." and i agree with your statement "The one time a 404 is problematic is if Google learned about the nonexistent URL from a link on your own site." Just a little correction which is based on my experience. ()

So we have site1. This site dropped from TOP 1 page 3-4 time during last 8 months(a know about google updates and it's not too much correlated/related with any on this updates) and i noticed that before that drops we had increase of 404 errors in GSC.

1st time one of the big ebook websites (warez) setup 301 redirect to this SITE1 and during 1 week we have +3-4k traffic with strange URLs - site1_com/word-for-dummies.html, so as result after 1 week we had 1-2 k error pages in GSC. At that time my main concern was to fix it - remove this urls via GSC tool, try to block that website, etc ....
After 1 week we dropped ... it was early sept 2016, after 2 weeks it was penguin update .. that's the reason why that time i didn't understand that it can be related.

We had 2 other such accidents later ... and after each such episode we dropped....

So, if there is any link (even from other website) to any page on your website - it will be better (faster) to setup 301 redirect, then to get 404 error. In that case you need to wait more ... of course i just talking about >100 page errors, not about 1 404 page in GSC.

Hope you understand what i mean.

thanks
6:11 pm on May 3, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13825
votes: 484


So, if there is any link (even from other website) to any page on your website - it will be better (faster) to setup 301 redirect

I'd say it depends on the linking site. If a worthless site is linking to imaginary pages on your site, then a 404 is appropriate because in the long run it tells Google's computer that those guys don't know what they're talking about. If it's a worthwhile site then figure out where they really meant to link to, and redirect accordingly.

Now, this is the Apache forum, meaning that there is an answer to your original question. If you never use parameters in URLs at all, you can append before the WP section of your htaccess
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} ^/(.*)
RewriteRule (^|/|\.html)$ http://example.com/%1? [R=301,L]
but don't copy and paste, because that's my site's version. The details of the pattern should be specific to your site. If the site uses parameters internally, but not in visible URLs, change the first Condition to
RewriteCond %{THE_REQUEST} \?
And if you use extensionless URLs, and you never have . (dot) in directory names, the pattern in the RewriteRule might be best expressed as
^[^.]+$
The idea here is to keep the server from even looking at conditions when you already know they won't be met.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members