Zen Follower
- Join Date:
- Oct 2007
- Posts:
- 415
- Plugin Contributions:
- 0
redirect obsolete links to a different page?
Is it possible to redirect a specific product page (only for one product) to for example index.php? If so, how? :blink:
Views: 9,299
Zen Follower
Is it possible to redirect a specific product page (only for one product) to for example index.php? If so, how? :blink:
Totally Zenned
Re-direct from where?
A "product page" is not a "page" in the sense you are thinking.
It is an amalgamation of scores of bits of data that are cobbled together and sent to a browser as HTML. It does not exist until it is needed, and when it is navigated out of, it "evaporates".
What is it that you are trying to do?
20 years a Zencart User
Zen Follower
I would like to redirect from a product page (the product is discontinued/sold out).
The reason why I want to do that is because there are several links from other domains pointing to that particular product page so since the product is discontinued I want to disable the product page and redirect to index when somebody clicks on the link from another domain.
Totally Zenned
You could probably build a conditional into an .htaccess file .
I don't know the syntax here, but others on the forum might pick this up.
In the meantime, search for redirect using .htaccess on Google
20 years a Zencart User
Totally Zenned
20 years a Zencart User
Inactive
Redirecting to your Home page would just confuse people. Better to do a proper redirect to a page you create -- using Define Pages or EZ Pages.
Example for your .htaccess if using Define Page:
Redirect 301 /path/to/old/url http://yourdomain/index.php?main_page=discontinued
The learning is in the doing.
Zen Follower
Thanks for the answers. Using .htaccess seems like a good idea, but where exactly do I put the file? I tried with:
redirect 301 old-url new-url
and placed the .htaccess file in the root, but it does not redirect.
Inactive
Check the syntax as it must be correct.
Redirect 301 / << must start with a slash http://... << must use correct URL to a page that works
Also check that permissions are 644 on the .htaccess file.
The learning is in the doing.
Zen Follower
Ok, Im trying to redirect:
http://www.usconverters.com/index.php?main_page=product_info&cPath=75&products_id=221
to:
http://www.usconverters.com/
(I will make a custom landing page later)
I added the following line in .htaccess in the root:
redirect 301 /index.php?main_page=product_info&cPath=75&products_id=221 http://www.usconverters.com
.htaccess is set to CHMOD 664
but as far as I can see then its not redirecting, any ideas? :blink:
Totally Zenned
I am not sure the static page redirect works on dynamic pages. I found this on Google try it:
Implementing a 301 redirect for dynamic pages
A dynamic page is one generated by a database driven application, such as blog or forum software. A file name is appended by a query string, looking something like this:
http://www.example.com/page.php?id=13
Where a query string is used, the 301 redirect solution for static pages above will not work; you'll need to use a rewrite solution. Using the page.php?id=13 example, here's what you'll need to use in your htaccess file:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]
In the example above the id=13 should be replaced with the query string of the page you wish to redirect and the page.php with the name of your file prior to the query string.
A more powerful set of directives for manipulating URLs is contained in the Apache mod_rewrite module, especially useful when changing domain names and/or folder names containing large numbers of files. Read our basic tutorial on the apache mod_rewrite module.
Zen Follower
Thanks a lot for the responses, unfortunately I still couldnt get this working using and of the methods. Seems like it quite complicated to redirect a dynamic page.
Inactive
DML73:
Ok, Im trying to redirect:
http://www.usconverters.com/index.php?main_page=product_info&cPath=75&products_id=221
to:
http://www.usconverters.com/
(I will make a custom landing page later)I added the following line in .htaccess in the root:
redirect 301 /index.php?main_page=product_info&cPath=75&products_id=221 http://www.usconverters.com
.htaccess is set to CHMOD 664
but as far as I can see then its not redirecting, any ideas? :blink:
http://www.usconverters.com/ << this is not a URL to a page
http://www.usconverters.com/index.php << this is a URL to a page
Which is why I mentioned earlier about first creating the page to be redirected to. Otherwise, we know life will get in the way and it could weeks or months before that page is created. In the meantime, you will have a lot of confused people and possibly missed Sales.
And using any type of SEO module for "pretty URLs" could cause problems with the redirect.
The learning is in the doing.
Zen Follower
Did anybody find out how to 301 redirect a single product page?
I tried all the suggestions in this thread but nothing works. I have no URL mods or anyhting like that installed.
New Zenner
Top of your .htaccess file should contain:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /store/
Note: Replace /store/ with the relative web path of your catalog. If store is in the root then just use: /
example: RewriteBase /
Then add:
#Old store URLs
RewriteRule ^OLD-PRODUCT.html$ "http://www.YOURDOMAIN.com/NEW-PRODUCT.html" [R=301,L]
RewriteRule ^OLD-PRODUCT2.html$ "http://www.YOURDOMAIN.com/NEW-PRODUCT2.html" [R=301,L]
So your .htaccess will contain:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /store/
#Old store URLs
RewriteRule ^OLD-PRODUCT.html$ "http://www.YOURDOMAIN.com/NEW-PRODUCT.html" [R=301,L]
RewriteRule ^OLD-PRODUCT2.html$ "http://www.YOURDOMAIN.com/NEW-PRODUCT2.html" [R=301,L]
Zen Follower
Please disregard the post immediately above.
You'll need this in the root .htaccess file:```
RewriteEngine On
RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=221$ [NC]
RewriteRule ^zencart/(index.php)?$ http://www.example.com/? [R=301,L]
This redirects product ID 221 for all categories, for both www and non-www requests, and whether or not "index.php" is within the request.
Change "zencart/" to your real folder name. Remove the "zencart/" part if the site is in the root folder. Note the trailing slash is also deleted.
Final point. Never mix RewriteRule directives with Redirect or RedirectMatch directives within the same site. If you do, you can never be quite sure of the processing order. By mixing them up, you're using directives from two different Apache modules. Stick to just using RewriteRule for all directives.
Online since 1995.
Zen Follower
Website Rob:
http://www.usconverters.com/ << this is not a URL to a page.
http://www.usconverters.com/index.php << this is a URL to a page.
Those two URLs are Duplicate Content for your site root. Only one of those should return 200 OK HTTP status.
The canonical URL is the one without the default index filename included.
The other should redirect to the canonical URL:```
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\ HTTP/
RewriteRule ^index.php$ http://www.example.com/? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index.php)??main_page=index(&cPath=)?\ HTTP/
RewriteRule ^(index.php)?$ http://www.example.com/? [R=301,L]
RewriteCond %{HTTP_HOST} !^(www.example.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
ErrorDocument 404 /index.php?main_page=page_not_found
If the store is located in a folder, add "/foldername" to both of the RewriteConds directly before the /index and before the /(index\.php) parts, and to the RewriteRule between the ^ and index\.php and between the ^ and (index\.php) parts, but add these in only the first two rulesets.
Online since 1995.
New Zenner
g1smd:
Please disregard the post immediately above.
My, My...
Has always worked for me - but perhaps I have other things going on in my .htaccess that requires me to do it the way I do...
Zen Follower
There's several problems with your code.
Firstly, it takes no account of query strings so cannot be used to solve this ZenCart question; and secondly, the literal target URL should not have any escaping within. Escaping is needed on literal periods, etc, only within the RegEx pattern (the bit "on the left"). Your code is also redirecting from folder to root, as the target URL does not contain a folder.
Online since 1995.
New Zenner
g1smd:
There's several problems with your code.
Firstly, it takes no account of query strings so cannot be used to solve this ZenCart question; and secondly, the literal target URL should not have any escaping within. Escaping is needed on literal periods, etc, only within the RegEx pattern (the bit "on the left"). Your code is also redirecting from folder to root, as the target URL does not contain a folder.
Ah, I THINK I see what you're saying -
We're using this code to redirect existing links that were once on an osCommerce shop to the new Zen Cart shop...
Zen Follower
For redirecting from /folder/ to root, you might find this code is a bit cleaner: http://www.zen-cart.com/forum/showthread.php?t=150620&page=2
Adjust the first chunk to suit your osCommerce URLs and place it in that folder. Ensure the second chunk, in the root, includes an exclusion for both the admin folder and for the folder where the osCommerce site used to reside (that's the !^/(admin|zencart) part of the code).
Online since 1995.
Tell staff why this post should be reviewed.