URL rewriting from subcategory to category
-
Hello everybody!
I have quite simple question about URL rewriting from subcategory to category, yet I can't find any solution to this problem (due to lack of my deeper apache programming knowledge).
Here is my problem/question:
we have two website url structures that causes dublicate problems:
1 and 2 pages are absolutely same (both also returns 200 OK). What we need is 301 redirect from 2 to 1 without any other deeper categories redirects (like www.website.com/language/category/1/169/ redirecting to .../category/1/ or .../category/).
Here goes .htaccess URL rewrite rules:
RewriteRule ^([^/]{1,3})/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /index.php?lang=$1&idr=$2&par1=$3&par2=$4&par3=$5&par4=$6&%{QUERY_STRING} [L]
RewriteRule ^([^/]{1,3})/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /index.php?lang=$1&idr=$2&par1=$3&par2=$4&par3=$5&%{QUERY_STRING} [L]
RewriteRule ^([^/]{1,3})/([^/]+)/([^/]+)/([^/]+)/$ /index.php?lang=$1&idr=$2&par1=$3&par2=$4&%{QUERY_STRING} [L]
RewriteRule ^([^/]{1,3})/([^/]+)/([^/]+)/$ /index.php?lang=$1&idr=$2&par1=$3&%{QUERY_STRING} [L]
RewriteRule ^([^/]{1,3})/([^/]+)/$ /index.php?lang=$1&idr=$2&%{QUERY_STRING} [L]
RewriteRule ^([^/]{1,3})/$ /index.php?lang=$1&%{QUERY_STRING} [L]
There are other redirects that handles non-www to www and related issues:
RedirectMatch 301 ^/lt/$ http://www.domain.lt/
RewriteCond %{HTTP_HOST} ^domain.lt
RewriteRule (.*) http://www.domain.lt/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.)/$RewriteRule ^(.)$ http://www.domain.lt/$1/ [R=301,L]
At this moment we cannot solve this problem with rel canonical (due to our CMS limits).
Thanks for your help guys!
If You need any other details on our coding, just let me know.
-
That's great! Glad to help anytime. Sha
-
Thank You very much! The code You provided worked very well and solved our problem.
-
Thanks Alan Mosley and Sha Menz! We will try to implement given advices tonight (at low traffic hours) and check back soon with results. Sha, thats ok with line breaks, we will figure it out. Thanks for your support once again!
-
Sorry that my answer appears to have lost all line breaks...seems to be some css issues at the moment.
Hoping you can copy it out and separate the lines ....I will try to reformat it as soon as I can, but right now it just keeps loading funky.
Sha
-
Hi kundrotas, The problem you have is that the code used for .htaccess functions is not terribly "intelligent". It does not allow for the use of "IF" statements etc. This being the case, the better option is to move the action to within the actual code. This is the rule at question RewriteRule ^([^/]{1,3})/([^/]+)/([^/]+)/$ /index.php?lang=$1&idr=$2&par1=$3&%{QUERY_STRING} [L] The easiest thing to do is in index.php add a check for par1 // If par1 is 1 and everything else is blank send it to the root. if( $par1 == '1' && $par2 == '' && $par3 == '' && $par4 == '' && $par5 == '' && $par6 == '' ) { $location = "/$lang/$idr/"; header ('HTTP/1.1 301 Moved Permanently'); header ('Location: '.$location); } Hope that helps, Sha
-
in windows on a IIS server it would be
<match url="^category/1$"><action type="Rewrite" url="category"></action></match>
i think in a htaccess file it would be sothing like
RewriteRule ="^/category/1$ http://www.domain.lt/category [R=301,L]
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Broken URL Links
Hi everyone, I have a question regarding broken URL links on my website. Late last year I move my site from an old platform to Shopify, and now have broken URL links giving out 4xx errors. When I look at Moz Pro>Campaigns>Insights>links, I can see the top broken URL links, however there is a difference if copy & paste URL directly from Moz Pro and by Export CSV file. For example below, If I copy and paste links direct from Moz Pro, it has the “http://” in front as below: http://www.thehairhub.com.au/WebRoot/ecshared01/Shops/thehairhub/57F3/1D8F/D244/C675/E27D/AC10/003F/35AD/manic-panic-colours.jpg But when I export the list of links as an CSV file, the http:// is removed. www.thehairhub.com.au/WebRoot/ecshared01/Shops/thehairhub/57F3/1D8F/D244/C675/E27D/AC10/003F/35AD/manic-panic-colours.jpg Another Example below: By copy & paste URL direct from Moz Pro
Technical SEO | | johnwall
http://thehairhub.com.au/Shop-Brands/Vitafive-CPR/CPR-Rescue By export CSV file.
thehairhub.com.au/Shop-Brands/Vitafive-CPR/CPR-Rescue Which one do I use to enter into the “Redirect From” field in Shopify URL Redirects? Do I need to have the http:// in front of the URL? Or is it not required for redirects to work? Kind Regards, John Wall
The Hair Hub0 -
Google selecting incorrect URL as canonical: 'Duplicate, submitted URL not selected as canonical'
Hi there, A number of our URLs are being de-indexed by Google. When looking into this using Google Search Console the same message is appearing on multiple pages across our sites: 'Duplicate, submitted URL not selected as canonical' 'IndexingIndexing allowed? YesUser-declared canonical - https://www.mrisoftware.com/ie/products/real-estate-financial-software/Google-selected canonical - https://www.mrisoftware.com/uk/products/real-estate-financial-software/'Has anyone else experienced this problem?How can I get Google to select the correct, user-declared canoncial? Thanks.
Technical SEO | | nfrank0 -
Which url should i use? Thanks!
I have a question regarding how to use my url, we are a Swedish-based website which have the url, http://interimslösning.se/ (that contains the Swedish letter “ö”) so the url can also be written as http://xn--interimslsning-3pb.se/. Which of the following url should I use for my backlinks, http://interimslösning.se/ or http://xn--interimslsning-3pb.se/ ? What is the difference between them regarding SEO? And is it good or bad to use letter like "ö" or other characters like that in your url? I was thinking that maybe it is good to use the letter "ö" for local search optimization in sweden, but i don't know.. Thanks in advance! Greetings,
Technical SEO | | Kiwibananlime
Paul Linderoth0 -
Magento Rewrite Issue
Moz's Crawler has thrown up a bunch of crawl issue for my site.The site is a magento based site and I recently updated the themes so some routes may have have become redundant. Moz has identified 289 pages with Temporary Redirect. I thought magento managed the redirects if I set the "Auto-redirect to Base URL" to Yes(301 Moved permanently). But this is enabled on my store and I still get the errors. The only thing I could think of was to add a Robots.txt and handle the redirection of these links from here. But handling redirection for 289 links is no mean task. I was looking for any ideas that could fix this without me manually doing this .
Technical SEO | | abhishek19860 -
Should I make a new URL just so it can include a target keyword, then 301 redirect the old URL?
This is for an ecommerce site, and the company I'm working with has started selling a new line of products they want to promote.Should I make a new URL just so it can include a target keyword, then 301 redirect the old URL? One of my concerns is losing a little bit of link value from redirecting. Thank you for reading!
Technical SEO | | DA20130 -
Removing Redirected URLs from XML Sitemap
If I'm updating a URL and 301 redirecting the old URL to the new URL, Google recommends I remove the old URL from our XML sitemap and add the new URL. That makes sense. However, can anyone speak to how Google transfers the ranking value (link value) from the old URL to the new URL? My suspicion is this happens outside the sitemap. If Google already has the old URL indexed, the next time it crawls that URL, Googlebot discovers the 301 redirect and that starts the process of URL value transfer. I guess my question revolves around whether removing the old URL (or the timing of the removal) from the sitemap can impact Googlebot's transfer of the old URL value to the new URL.
Technical SEO | | RyanOD0 -
Friendly URLs
Hi, I have an important news site and I am trying to implement user friendly URLs. Now, when you click a news in the homepage, it goes to a redirect.php page and then goes to a friendly url. the question is, It is better to have the friendly URL in the first link or it is the same for the robot having this in the finally url? Thanks
Technical SEO | | informatica8100 -
Repeating brand name on all subcategory levels
As part consolidating our site navigation, I have an opportunity to change how we name url s on child pages. At present, I think there are 2 problems that could be fixed.
Technical SEO | | stephenfishman
1.As you drill down, the brand name is not part of each url.
2. Also, the urls show abreviations that are not customer friendly. Are these worth changing? I am redirecting pages whether I change the naming or not. Below is my current navigation and below that the changed navigation I am considering. Many thanks to all that look and share their thoughts. Handcrafter --- details -- This is an e-commerce site with on hand products and similar products which are custom ordered from a catalog: Current Navigation Drill Down: /ctgy/brandname.html /ctgy/brandname-onh.html
/ctgy/onhmir.html then the specific products:
/onhmir/30322-onhmir92_741.html
/onhmir/30324-onhmir96_743.html The catalog has more products and so has 1 extra level of child category pages:
ctgy/brandname.html
/ctgy/brandname-cat.html
/ctgy/brandname-catmir.html
/ctgy/design1catmir.html
/ctgy/design2catmir.html then the specific products:
/catmir/30322-catmirhappy.html
/catmir/30324-catmirhappy.html Changed Naming Under Consideration:
On pages above the product page, (category pages) spell out all words and place the brand name in the parent url. The result would be: /ctgy/brandname.html /ctgy/brandname-on-hand.html
/ctgy/brandname-on-hand-mirror.html then the specific products:
/brandname-on-hand-mirror/30322-onh-mir92_741.html
/brandname-on-hand-mirror/30324-on-hand-mir96_743.html The catalog has more products and so has 1 extra level of child category pages: /ctgy/brandname-catalog.html
/ctgy/brandname-catalog-mirror.html
/ctgy/brandname-catalog-mirror-style1.html
ctgy/brandname-catalog-mirror-style2.html then the specific products:
/brandname-catalog-mirror-style1/30322-cat-mirhappy.html
/brandname-catalog-mirror-style1/30324-cat-mirhappy.html0