Forum Moderators: phranque

Message Too Old, No Replies

Need help with rewrite, can anyone help (being sniped as they call it)

         

concepts99

1:39 am on Jan 22, 2007 (gmt 0)

10+ Year Member



It seems like we are being sniped, someone is creating duplicate pages on our site and submitted it to the search engines to get us banned.

For example

sitename/prod=1
and
sitename/prod=1&7566

will show the same product, but the search engines are picking up both

I want to catch all the ones with an & sign AND prod=xx and send it to a 301 (thats the correct way to do it right?)

only if it is

sitename/prod=1%7566 (send to 301)
instead of
sitename/cat=1%7566 (do not send to 301)
sitename/prod=1 (do not send to 301)

Can anyone help? And this is a disgusting act that was forced onto us.

concepts99

3:01 am on Jan 22, 2007 (gmt 0)

10+ Year Member



I want to sitename/prod=1%7566 (send to 301 BACK to "sitename/prod=1"

Is this correct and best way to do it?

jdMorgan

3:02 am on Jan 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like:

RewriteRule ^prod=([^&]+)& http://www.example.com/prod=$1 [R=301,L]

I'm assuming that this "prod=" stuff is actually part of your URL as you showed it, and not in a query string attached to the URL. I'm also assuming you have other rewriterules and so already have the setup directives required to enable mod_rewrite.

This code snippet is intended for use in .htaccess, and will need the usual modification for use in httpd.conf or other server config files.

Jim

concepts99

3:28 am on Jan 22, 2007 (gmt 0)

10+ Year Member



Actually my tag is like this, can you help with a rewrite

[domain...]

#*$!X is always different (a number), I just want to strip OFF everything with the & sign and after then redirect to

[domain...]

I am new to this, will this rewrite the URL and redirect to the URL stripping off & and everything afterwards? Is this all the code I need?

Thanks for your help.

jdMorgan

3:33 pm on Jan 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Placed in .htaccess in the "/subdomain/" directory, something this should work for all (subdomain) subdirectories in that directory:

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

Redirect
/subdomain/subdomain2/product.php?productid=abcNNN&<anything> --> /subdomain/subdomain2/product.php?productid=abcNNN

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

concepts99

11:53 pm on Jan 22, 2007 (gmt 0)

10+ Year Member



I copied the above verbatim and put it in the subdomain2 directory .htaccess

I am trying to edit something in

domain.com/subdomain/subdomain2/product.php

and put in

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{QUERY_STRING} ^productid=([^&]*)&
RewriteRule ^([^/])+/product\.php$ [domainname.com...] [R=301,L]

and it didnt work, I also tried to put it in .htaccess in subdomain directory.

I also have a
DirectoryIndex home.php
on the to of the page in .htaccess

I do have mod rewrite module installed on my server, linux. What am I doing wrong?

jdMorgan

11:59 pm on Jan 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe nothing wrong... I mis-typed:

RewriteCond %{QUERY_STRING} ^productid=([^&]*)&
RewriteRule ^[b]([^/]+)/[/b]product\.php$ http://www.example.com/$1/product.php?productid=%1 [R=301,L]

Jim

concepts99

1:03 am on Jan 23, 2007 (gmt 0)

10+ Year Member



Thanks for your help so far, I am reading the tutorials you gave me and it mentions

Mod_rewrite cannot "change" the URLs on your pages

First, the misconception: Mod_rewrite cannot be used to change the URL that the visitor sees in his/her browser address bar unless an external redirect is invoked. But an external redirect would 'expose' the underlying dynamic URL to search engines and would therefore completely defeat the purpose here. This application calls for an internal server rewrite, not an external client redirect.

Is this true, am I looking for a new URL in my browser? If not, how do I test to see if it is working?

Because right now, with the corrected code you gave me, it does not seem to be working, (no new URL)

Do I need to restart the apache service?

Here is a copy of my httpd.conf file

#
# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# permissions.
#
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">

#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#

Options Indexes FollowSymLinks MultiViews Includes

#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#

AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>

#
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: [httpd.apache.org...]
#
#<IfModule mod_userdir.c>
# UserDir public_html
#</IfModule>

jdMorgan

1:55 am on Jan 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I missed this, too:

> I copied the above verbatim and put it in the subdomain2 directory .htaccess
>
> domain.com/subdomain/subdomain2/product.php

The quote you cited does not apply to what you are doing here. I addressed that article to a different kind of problem. You are in fact doing an external redirect here, while that article discusses internal rewrites primarily.

The code, as originally stated above, was intended for use in domain.com/subdomain/.htaccess, and not for use in domain.com/subdomain/subdomain2/.htaccess

If you wish the code to be located in the .htaccess file at domain.com/subdomain/subdomain2/.htaccess and to have effect *only* in the subdomain2 subdirectory, then it would need to be modified:


RewriteCond %{QUERY_STRING} ^productid=([^&]*)&
RewriteRule ^product\.php$ http://www.example.com/subdomain/subdomain2/product.php?productid=%1 [R=301,L]

The RewriteRule pattern and the substitution URL are both highly-sensitive to the location of the .htaccess file containing the code. The pattern must be adjusted to match the desired local (per-directory) URL-path, and the substitution must specify the full and correct destination URL.

You do not have to restart Apache unless you make changes to httpd.conf, conf.d, or another included server-configuration-level file; It is not necessary to restart after changes to .htaccess.

However, after making any change to *any* of these files --including .htaccess-- it will be necessary to flush your browser cache (or delete the Temporary Internet Files if you use MSIE). Otherwise, when you request a URL that should be rewritten or redirected, your browser may simply display a copy of the page that it has previously cached; In this case, your browser won't even send the request to your server, so obviously your server-side code can and will have no effect. So, flushing the cache guarantees that your browser will actually send the request to your server, and you will then see a "fresh" result.

Jim

concepts99

2:29 am on Jan 23, 2007 (gmt 0)

10+ Year Member



Thank you for the great help. It works great.

I am so glad I found this forum (I am a supporter).