Forum Moderators: phranque

Message Too Old, No Replies

301 redirect issue once again

         

zeus

4:45 pm on Sep 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can I redirect to the original - example

/gallery/bla/bla2?noCount=1
/gallery/bla/bla2?full=1

now here I want to remove ?noCount=1 and other example ?full=1

so its /gallery/bla/bla2/

I think I need a 301

g1smd

5:23 pm on Sep 29, 2011 (gmt 0)

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



You do.

It's two lines of code for each redirect, a RewriteCond looking at QUERY_STRING and the usual RewriteRule with [R=301,L] flags.

There's hundreds of examples in this forum.

lucy24

9:29 pm on Sep 29, 2011 (gmt 0)

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



/gallery/bla/bla2?noCount=1
/gallery/bla/bla2?full=1

now here I want to remove ?noCount=1 and other example ?full=1

so its /gallery/bla/bla2/

Wait. You're saying two different things. If you're merely removing the query, you don't end up with the directory

/gallery/bla/bla2/

you end up with the file

/gallery/bla/bla2

--which may or may not turn into the "bla2" directory depending on what else is going on in your htaccess and what other mods you've got installed.

As currently written, where do those urls take you? To /bla2/index.php, or to /bla2.php?

zeus

4:13 pm on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what i want is www.mydomain.com/gallery/cat2/topic

thats how i want it, but now i often see ?noCount=1 and ?full=1 at the end of the url, I want that to be redirected to the real url mentioned at top.

wilderness

4:46 pm on Oct 6, 2011 (gmt 0)

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



disregard.

Search the archives using the following (exactly)!

"QUERY_STRING" + "[R=301,L]"

zeus

5:26 pm on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I will try a search be cause my problem was also what search keyword could i use for this situation.

zeus

9:51 pm on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hmm dont get it, have tried a few things, but did not work, im absolute no apache dude.

lucy24

10:12 pm on Oct 6, 2011 (gmt 0)

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



Well, let's see those "few things" and then we will have some idea how close you are.

Oh, and as long as you're searching for "query string", there are a couple of different threads where I pasted in the full boilerplate about query strings and htaccess. Can't guarantee that every single word is absolutely perfect, but so far no cries of Don't listen to her! She's delusional! This will make your server have a terminal meltdown!

zeus

8:23 pm on Oct 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/gallery/bla/bla2?noCount=1
/gallery/bla/bla2?full=1

now here I want to remove ?noCount=1 and other example ?full=1

so its /gallery/bla/bla2

Now I have tried this and that, but its hard to find anything related, special when one have no clue about apache. Any one here that can create the code?

RewriteRule ^(.*)$ /$1? [R=301,L] this dont work

g1smd

9:35 pm on Oct 10, 2011 (gmt 0)

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



You need RewriteCond %{QUERY_STRING} . before the rule, to ensure the rule runs only when there is a query string to remove.

The RewriteRule target should include the protocol and domain name.

zeus

9:47 pm on Oct 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteCond %{QUERY_STRING} .
RewriteRule ^([^/]+)/(.+)$ [mydomain.com...] [R=301,L]

but there is two pages where this dont work in a quick test, so im not sure if the code is 100% els it works

g1smd

9:53 pm on Oct 10, 2011 (gmt 0)

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



You code clearly will not work for the root home page or for any file within the root folder.

It will only work for URLs one, or more than one, folder level deep. Is that what you want?

zeus

9:58 pm on Oct 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yep the "bad pages" are all in the folder gallery

zeus

7:06 pm on Nov 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteRule ^([^/]+)/(.+)$ mydomain.com/gallery [R=301,L]

hmm somehow it does not work now.

I want that ?noCount=1 and ?full=1 is removed, means a 301 to original ex. mydomain.com/gallery/bla2-cat/bla2

mydomain.com/gallery/bla2-cat/bla2?noCount=1

mydomain.com/gallery/bla-cat/bla?full=1

lucy24

11:04 pm on Nov 21, 2011 (gmt 0)

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



C'mon, Zeus, you've been around long enough to know that "it does not work" is not the correct wording ;)

Do you want to remove the entire query string, or just the two specific elements "noCount" and "full"?

Your rule as currently written will only work for deeper-level files, not for the Index file.

Oh, wait. This is an old thread. We've been over that already. The generic include-everything formula is

(([^/]+/)*[^/]*)

meaning "zero or more directories followed by zero or more document names". And the ultra-generic formula is

(.*)

meaning "oh, just grab everything". Both of these can only come at the end of your RegEx. That is, there can --optionally-- be specific stuff before them, but nothing after. Unless your server is running too fast and you want to slow it down.

zeus

11:17 pm on Nov 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lucy24 - yes been here a long time the problem is just rewrite is not my field at all, im more a manager and knowledge about seo for images. So I need the code writen but maybe I will see more posts, thanks

g1smd

7:21 am on Nov 22, 2011 (gmt 0)

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



In Google: [site:webmasterworld.com RewriteRule remove query string].

The only response to "it's not working" is "because you made an error". Without knowing what it actually does, there's no clue as to what needs fixing. :)

zeus

3:16 pm on Nov 22, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteEngine on
RewriteCond %{QUERY_STRING} .
RewriteRule ^([^/]+)/(.+)$ mydomain.com/gallery/ [R=301,L]

I have been looking all day tried all kind of codes, I have placed the .htaccess root, the pages where i want changes are in gallery

lucy24

11:21 pm on Nov 22, 2011 (gmt 0)

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



To repeat:
Do you want to remove the entire query string, or just the two specific elements "noCount" and "full"?


This will make the difference between "slightly tricky" and "you can do it on your head".

It is OK for the htaccess to be in the root. In fact it is generally better to have only one htaccess for the whole domain-- assuming shared hosting so you can't shove it all into the config file. That doesn't count trivial stuff like directory-specific indexing or custom error pages. (That is, I don't count it, because this type of command should have no effect on anything else.)