Forum Moderators: phranque

Message Too Old, No Replies

Rewrite /?*anything* to http://example.com/

         

jpietrowiak

2:04 am on Mar 28, 2009 (gmt 0)

10+ Year Member



Hi all,
I have been struggling with this to no avail. Should be simple but I need to redirect any page from site.com/?(with anything after it) to site.com. I made an accident rewriting from an old site to the new site and my ranking suffered dramatically since it shows so many duplicate home pages.

Redirect http://sub.example.com/(nothinghere)?(anything after here) to http://sub.example.com

So in other words:
Redirect http://sub.example.com/?**** to http://sub.example.com

[edited by: jdMorgan at 3:13 am (utc) on Mar. 28, 2009]
[edit reason] example.com [/edit]

jpietrowiak

3:12 am on Mar 28, 2009 (gmt 0)

10+ Year Member



One note is that the question mark is write where you see it. There is nothing before it because of a bad URL rewrite. There are many pages indexed in SE that I want to disappear and all point to the home page and do not error out because there is nothing between / and ?. If there were it would return a page not found error which would be ok if it did this as well.

jdMorgan

3:14 am on Mar 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I have been struggling with this to no avail.

Please post your own best-effort code as a basis for discussion.

Thanks,
Jim

jpietrowiak

7:53 am on Mar 28, 2009 (gmt 0)

10+ Year Member



Ok another couple hours and I have some progress on the URLs but not sure of the result. It at least redirects some of the URLS. I believe its giving a 404 and redirecting to my home page at least. If I get rid of the id= to make it anything then the server errors.

RewriteCond %{QUERY_STRING} &?id=(.*)$ [NC]
RewriteRule ^$ / [R=301,NC,L]

g1smd

8:07 am on Mar 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




A URL like example.com/?param=value is a perfectly acceptable URL format, but example.com/index.php?param=value is a duplicate of it. The shorter version should be the preferred format.

Do you want to redirect for all query strings, or just those with id= in them?

Is this just for the root page, or for all pages (filename part) of the site?

A redirect should contain full domain name in the target URL.

# Redirect root with non-blank query-string to root without query string
RewriteCond %{QUERY_STRING} [b].[/b]
RewriteRule ^$ http://www.example.com/[b]?[/b] [R=301,L]

The reason for your error is an infinite loop when the query-string is re-appended and that matches your pattern again.

Use a question mark to clear the query string value.

This rule does not fix requests asking for index.html with query-string. Those also need to be fixed, as you should refer to your index pages without using their filename in the URL.

jpietrowiak

7:53 pm on Mar 28, 2009 (gmt 0)

10+ Year Member



" Do you want to redirect for all query strings, or just those with id= in them?" The problem is that I use vbulletin now instead of punbb. So the format is different though I believe they still use Query. But from what I could see they would always have something between the question mark and /.

"Is this just for the root page, or for all pages (filename part) of the site? "
It seems from my mistake of a bad URL perminant redirect that the SE indexed many pages and they are all like this format [sub.site.com...] a bunch of stuff here some id=#### some ?action=show_user&user_id=104.

Thanks
I will play with your suggestion to see how it works out.

jpietrowiak

8:13 pm on Mar 28, 2009 (gmt 0)

10+ Year Member



Ok I tried it out and seems to be working. What does this actually specifically look at so I know in the future if this will affect anything else that I may put in my forum or site? Is it specifically that there is nothing between "/" and "?" then redirect to a page? because my form with pages and ? are working ok.

Thanks