Forum Moderators: phranque
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.
RewriteRule ^prod=([^&]+)& http://www.example.com/prod=$1 [R=301,L]
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
[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.
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
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?
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>
> 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]
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