redirect url with pattern in htaccess - .htaccess

I have a magento site where I am redirecting some urls to new urls in htaccess
olds urls is like this domain.com/dinnerware-24.html and its number is From 1 to 99 and it is dynamic
now i want create pattern if my url have number, delete it automaticly and redirect to new url e.g
domain.com/dinnerware-25?q=1 or domain.com/dinnerware-99.html
redirect to domain.com/dinnerware?q=1 and domain.com/dinnerware.html

This happens if you have duplicate url's. In some older Magento versions this behaviour is also buggy and leads to urls with new increments after each reindex.
A solution would be to delete values of "url_path" attribute from catalog_product_entity_varchar table, truncate core_url_rewrite table and do a fresh reindex
You may consider to manually add some unique suffixes to your products or categories "name" or "url_key" attribute, to avoid this behaviour in the first place.
There is also a downside of deleting old redirects. From SEO point of view you may lose linkjuice that was distributed from old urls

Related

RewriteRule - redirect multi variable URL to multi variable URL

Our old website has a search URL structure like this:
example.com/Country/United States/Region/California/Area/Southern California/City/San Diego/Suburb/South Park/Type/House/Bedrooms/4/Bathrooms/3/
This is currently rewritten to point to the physical page:
/search/index.aspx
The parameters in the URL can be mixed up in different orders, and the URL can include one or more parameters.
We want to 301 redirect these old URLs to a new structure that is ordered in a logical way and more concise:
example.com/united-states/california/southern-california/san-diego/south-park/?type=house&bedrooms=4&bathrooms=3
example.com/united-states/california/?type=house&bedrooms=4&bathrooms=3
Is there a way with URL rewriting to interrogate the old URL, work out what parameters are existing and then write out the new URL structure?
Even if we can limit it to just the Country, Region, Area, City and Suburb, that may be good enough to at least return some results even if it's not perfect.
Also, spaces should be turned into hyphens and all text made lowercase.
I already have the RewriteRule to turn the new URL structure into a URL to point to a physical page. It's just transforming the old URL in to the new URL I need help with. I've googled endlessly and it's just beyond me!
Can anyone help? Thanks.
Since you already have the old search page with rewriting rules set up for it and which is capable of parsing all parameters you need, the easiest and most appropriate solution I see here is to issue a redirect you require from this old search page's code. Just put the code that composes new URL with all parameters needed and redirects from this page - this should be a lot easier than trying to parse all these parameters in .htaccess and combine them into the new format.

Rewrite condition to remove specific parameter in Prestashop

I have around 1000 categories created in prestashop and I have SPSEARCHPRO module installed. This module enables me to live search though my products.
Live search doesn't work due to the high number of categories but if I search normally it doesn't work either because the cat_id are included in the link and the link is too long. I suppose that's why the live search doesn't work either.
Here is what I'm trying to do:
I have this link:
https://example.com/en/module/spsearchpro/catesearch?fc=module&module=spsearchpro&controller=catesearch&orderby=name&orderway=desc&cat_id=2%2C4%2C(etc etc etc etc etc)
how can I remove the cat_id parameter from the link because the value is too long, it includes all the category id's.
I'm on prestashop 1.6.1.9 with multistore enabled (I don't know if that matters).
Putting this early in your .htaccess should cut out the unwanted parameter when the path ends with the category search slug, you may need to add other slugs to that if there are more affected pages.
RewriteCond %{QUERY_STRING} ^(.*?&)?cat_id=(?>[^&]*)(?:&(.*))?$
RewriteRule ^.*/catesearch$ /$0?%1%2 [NS,DPI,PT]
You may have to use L,R instead of DPI,PT flags if PrestaShop doesn't trust the $_GET it starts with (which comes from the rewritten URL). I'm unsure because it looks like it re-parses the URL from $_SERVER['REQUEST_URI'] which is unchanged by rewriting and would overwrite the corrected parameters with the original undesired ones. It may be the only way to make it work is an external redirect.

Magento increasing URL rewrites constantly

I have a Magento 1.7.0.2 installation and noticed the URL rewrites have been increasing recently.
For example:
Request path: product-27x27-4804.html
Target path : product-27x27-4805.html
All the new rewrites are custom ones and what I've noticed the count increases upon reindex.
These new rewrites are not valid and are basically junk I need to clean safely but at the same time make them stop from appearing again.
Any idea? Thanks!
There are two parts to this:
cleaning up the large URL rewrite table which will slow down your reindexes.
PLEASE BACKUP FIRST!
DELETE FROM core_url_rewrite WHERE category_id IS NOT NULL AND product_id IS NOT NULL;
patching magento to prevent the issue from occurring again. See link below for this, but DON'T follow the part that suggests you should truncate the whole core_url_rewrite table. That will remove all of your custom URL rewrites as well as the system.
https://magento.stackexchange.com/questions/17553/magento-core-url-rewrite-table-excessively-large

Complicated URL Rewrite for products that includes string manipulation

I am looking to rewrite approximately 5000 old product urls and I'm thinking that a rewrite rule in my .haccess file might do the trick, although creating this is too advanced for me.
Old Url Example:
Please keep in mind that the "68p4963" is randomly generated.
http://www.example.com/store/pc/Strapless-Monarch-Butterfly-Fairy-Wings-68p4963.htm
Preferred Url example:
This should now have a 301 redirect without the "www." and with the product name converted to lowercase.
http://example.com/products/strapless-monarch-butterfly-fairy-wings
Thank you.

Redesigned website: New URL structure: 301 Redirecting all old URLs

I have about 5500 indexed URLs in Google on my website and will soon launch a redesigned version of it with a brand new URL structure.
Because of thousands of backlinks I want to redirect all my old urls to the new ones using htaccess 301 redirect.
The problem is, it takes forever to manually write the htaccess-rules in Excel because I have to match all the new urls with the old ones.
I.e. this is how my Excel document would be set up:
| Old url | New url | htaccess rule |
/default/category/product-id/my-product | /category/my-product/ | 301 redirect /default/category/product-id/my-product http://mydomain.com/category/my-product/
Is there any way (software/service/tool) to match these urls based on the product name inside of the url so I don't have to do all this manually???
There are two ways I can think of:
you can use a HTTP Module which reads the excel and loads in to key-value pair as old and new URL and put it in cache. Then in the BeginRequest, if the URL (old url) is found in the key, do response.redirect to new page. You can add 301 header here which will make sure the browser gets message that this is permanently redirected.
Check CodeProject Article
If all your old and new url has got some pattern you can your IIS ReWrite module and use RegEx to create rule for the redirect.
Check IIS ReWrite Module
Hope that helps.
Milind
Assuming your old URLs are all in the format /default/category/product-id/my-product, then you can use formulas to get the next 2 cells
in B1, the new URL is construncted using /category/ and the text after the 4th/`:
="/category/"&MID(A1,FIND("/",A1,FIND("/",A1,FIND("/",A1,2)+1)+1)+1,99)&"/"
in C1, we can use those 2 values to construct the new redirect:
="301 redirect "&A1&" http://mydomain.com"&B1

Resources