Forum Moderators: phranque

Message Too Old, No Replies

Remove query string

         

greennature

7:03 pm on Dec 4, 2005 (gmt 0)



I'm using gallery and it appends a query string of?full=1 after every url

That is a duplicate url, i.e., if you remove the query string, the same url shows up. How do I remove it?

I've tried
RewriteCond %{QUERY_STRING} (.*)/(.*)fulll=1 [NC]
RewriteRule ^(.*)/(.*)$1? [R=301,L]

and it does not work

The command above it in .hatccess is the original rewrite command
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/([A-Za-z_0-9\-]+)$ /gallery/view_photo.php?set_albumName=$1&id=$2 [QSA]

the problem is with the end of that command id=$2
id is the picture name that can come out with either "picturename" or "picturename?full=1"

jdMorgan

7:26 pm on Dec 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{QUERY_STRING} ^(.+)\?full=1$
RewriteRule ^gallery/view_photo\.php$ http://www.example.com/gallery/view_photo.php?%1 [R=301,L]

But you'll need to fix the root cause of this in the gallery script before rewriting will do you much good with the search engine dup-content problem.

Jim

greennature

8:53 pm on Dec 4, 2005 (gmt 0)



Thanks JD, it did not work.
I think because it is missing the albumname parameter

after view_photo.php? in the original rewrite there is the set_albumName=$1

which returns the url

/gallery/albumname/picture

also, I've been trying to hack the code in the gallery file for a week because I see exactly where the problem is,
------------------
if ($gallery->album->isResized($index) &&!$do_fullOnly) {
if ($full) {
echo "<a href=" . makeAlbumUrl($gallery->session->albumName, $id) . ">";
} else if ($gallery->user->canViewFullImages($gallery->album)) {
echo "<a href=" . makeAlbumUrl($gallery->session->albumName, $id, array("full" => 1)) . ">";
}
$openAnchor = 1;
---------------------

The problem is with the
---------------------------
echo "<a href=" . makeAlbumUrl($gallery->session->albumName, $id, array("full" => 1)) . ">";
---------------

even if you change that line of code to the original line
-------------------
if ($full) {
echo "<a href=" . makeAlbumUrl($gallery->session->albumName, $id) . ">";
-----------------

You will still be able to pick up the?full=1 string.

I figured the problem was not with the code but with the rewrite, because you can type in any query string after the url and it works

i.e., instead of having?full=1 at the end of the url, you can use?yourname=2167 or
?ilikemydog=45 and the url works

jdMorgan

9:09 pm on Dec 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't understand what you're trying to tell me, but the code I posted will strip "?full=1" from the end of any query string attached to gallery/view_photo.php and redirect, leaving the other query parameters as they were. (The variable %1 contains the query string that preceded "?full=1")

Jim

greennature

11:19 pm on Dec 4, 2005 (gmt 0)



You said,

"I don't understand what you're trying to tell me",

reply: The entire second portion of the post referred to your comment about having to solve the problem in the script.

You also said,

"but the code I posted will strip "?full=1" from the end of any query string attached to gallery/view_photo.php and redirect, leaving the other query parameters as they were. (The variable %1 contains the query string that preceded "?full=1")"

ok, I understand that. I was mistaken to talk about the albumname

The problem is that view_photo.php was already rewritten in the previous command.

RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/([A-Za-z_0-9\-]+)$ /gallery/view_photo.php?set_albumName=$1&id=$2 [QSA]

All of my photos are already rewritten to
^([^.\?/]+)/([A-Za-z_0-9\-]+)$
which means
gallery/albumname/picture

so, I'm trying to remove the string from
gallery/albumname/picture?full=1

not from
gallery/view_photo.php...?full=1

jdMorgan

3:03 am on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, OK, got it now...

In that case, it's even simpler:


RewriteCond %{QUERY_STRING} .
RewriteRule ^gallery/([^/]+)/(.+)$ http://www.example.com/gallery/$1/$2? [R=301,L]

If /gallery/albumname/picture is requested with *any* non-blank query string appended, the query will be stripped and the client redirected to the URL with no query.

Jim

greennature

12:53 am on Dec 6, 2005 (gmt 0)



my academic background is International Relations and I do believe I can solve the problem of peace in Iraq faster than I can solve this rewrite problem :(

The solution, unfortunately did not work, and I tried a few variations on the theme.

Would the other rewrite conditions in .htaccess be the problem?

RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/([0-9]+)$ /gallery/view_photo.php?set_albumName=$1&index=$2 [QSA]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/([A-Za-z_0-9\-]+)$ /gallery/view_photo.php?set_albumName=$1&id=$2 [QSA]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/$ /gallery/$1 [R]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)$ /gallery/view_album.php?set_albumName=$1 [QSA]

jdMorgan

3:43 am on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The devil is in the details with this stuff. If one single character is out of place, the code will either either fail or cause inefficiencies.

Post your code with the latest new rule in place, and let's have a look at *all* of the rules that apply to these URLs.

Thanks,
Jim

greennature

4:43 am on Dec 6, 2005 (gmt 0)



This is the entire .htaccss except I changed my real domain for "example"
-----------------------

ErrorDocument 404 /error.php
DirectoryIndex index.php
php_value post_max_size 20971520
php_value upload_max_filesize 20971520
php_value magic_quotes_gpc off
php_flag session.bug_compat_warn off

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /gallery/
RewriteCond %{HTTP_HOST}!^example.com [NC]
RewriteRule ^(.*)$ http://example.com/gallery/$1 [R=301]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/([0-9]+)$ /gallery/view_photo.php?set_albumName=$1&index=$2 [QSA]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/([A-Za-z_0-9\-]+)$ /gallery/view_photo.php?set_albumName=$1&id=$2 [QSA]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)/$ /gallery/$1 [R]
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^.\?/]+)$ /gallery/view_album.php?set_albumName=$1 [QSA]
RewriteCond %{QUERY_STRING} .
RewriteRule ^gallery/([^/]+)/(.+)$ http://example.com/gallery/$1/$2? [R=301,L]
</IfModule>

jdMorgan

2:18 pm on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, you're using RewriteBase --- So get rid of "gallery" in the pattern (only in the pattern, make it look like the others) of the new rule, and try it like that.

RewriteRule ^([^/]+)/(.+)$ http://example.com/gallery/$1/$2? [R=301,L]

Jim

greennature

6:04 pm on Dec 6, 2005 (gmt 0)



did not work...

I'm wondering about that query string and others on all websites now.

For example, if you put?full=1 at the end of the url on this page

[webmasterworld.com...]

the page still shows up.

I tried it on many different pages around the net and it seems to work on over 90% of the pages. It even works for the New York Times.

So, it's not only my site. However, for my specific site, it is suppose to mean, view the image in "full" mode rather than view the image in resized mode.

Since I do not resize any of my images I do not use the "full view" option.

greennature

6:12 pm on Dec 6, 2005 (gmt 0)



I forgot to add that I only discovered this issue because after 4 years of good placement in Yahoo, my site disappeared from the SERPS during their last update.

When I studied their listings of my site I found three big problems of duplicate content. Their spider went wild on my site creating a bunch of strange urls I never saw before.

I overhauled my entire site with new software and I've tried to make it duplicate free by using .htaccess, robots.txt, etc. This is the only issue I have not resolved.

Since Yahoo has not updated its SERPS for my site in over a month, I can not tell how well the fixes have worked. I can check urls and headers to see that they've worked on my side.