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
-
Backlinks that go to a redirected URL
Hey guys, just wondering, my client has 3 websites, 2 of 3 will be closed down and the domains will be permanently redirected to the 1 primary domain - however they have some high quality backlinks pointing the domains that will be redirected. How does this effective SEO? Domain One (primary - getting redesign and rebuilt) - not many backlinks
Technical SEO | | thinkLukeSEO
Domain Two (will redirect to Domain One) - has quality backlinks
Domain Three (will redirect to Domain One) - has quality backlinks When the new website is launched on Domain One I will contact the backlink providers and request they update their URL - i assume that would be the best.0 -
Friendly URLs for MultiLingual Site
Hi, We have a multilingual website with both latin and non-latin characters, We are working on creating a friendly URL structure for the site. For the Latin languages can we use translated version of the URLs within the language folders? For example - www.site/cars www.site/fr/voitures www.site/es/autos
Technical SEO | | theLotter0 -
Cost/Benefit of modifying a URL
Just as the title says, I'm looking for the cost/benefit breakdown of modifying a URL for SEO purposes. What are some examples of issues where the benefit outweighs the cost, and vise-versa? Thanks all! Frank
Technical SEO | | FrankSweeney0 -
Index or Noindex Wordpress Categories?
I've read a few different opinions on this, but I'm still unclear as to the best practice. I use my categories more like tags. Let's say I write a post about about seo, local marketing, and indexing. I would use the categories "seo"+"marketing"+"indexing". Therefore, that same post will show up in all three category pages. If these category pages are all set to be indexed, what impact does that have on my post being indexed? Should I noindex all of the categories except for the main ones to avoid too much duplicate content? Or do you recommend noindexing all of the categories? I know some seo plugins make this easy to do (I'm using Yoast). The only reason I'm hesitant to noindex all categories is because some of them rank well for their subject. I also already tried noindexing about a month ago and lost a lot of blog traffic, so I reversed it. Now some of my category pages have overtaken my post rankings, which makes it harder for the reader to find the content, but my overall blog traffic is back up. With my situation, what is the best thing to do long term? I just started using my blog a lot more so I want to know that I have it setup correctly. Thanks in advance!
Technical SEO | | ChaseH0 -
Do sub-categories and categories behave similarly in WordPress?
Hi, I'm aware of the SEO benefit in category pages and would like to implement them on my (client's) site. Unfortunately, the developer set up the blog where there is one parent category called 'blog' and the rest of the categories are sub-categories, underneath the parent. While it seems like an easy fix, he claims that it's not because of some programmer jargon I can't understand. So my question is, can subcategories offer same or similar value as categories, or do I go head to head with this charming guy?
Technical SEO | | 5225Marketing0 -
URL content format - Any impact on SEO
I understand that there is a suggested maximum length for a URL so as not to be penalized by search engines. I'm wondering if I should if should optimize our ecommerce categories to be descriptive or use abbreviations to help keep the URL length to a minimum? Our products are segmented into many categories, so many products URL's are pretty long if we go the descriptive route. I've also heard that removing the category component entirely from a product URL can also be considered. I'm fairly new to all this SEO stuff, so I'm hoping the community can share their knowledge on the impact of these options. Cheers, Steve
Technical SEO | | SteveMaguire0 -
New website with slightly new urls
Hi we recently designed our website in work and changed some of the urls. the old site used to be http://www.example.ie/contact-us.htm now it's is http://example.ie/get-in-touch The problem we are having is with sitelinks (the ones auto generate in the serp) ie: about, contact us, team etc etc. Once cliked on, these OLD links are all going to 404 pages because of the change of url. Help with this would be greatly appreciated - I was thinking of blocking these old sitelinks in google web master.
Technical SEO | | GlenBOB0 -
Mod Rewrite Help
I need some help with doing the Mod Rewrite on our htaccess file. Basically I've a URL like this : www.example.co.uk/new-toy-search?keys=xbox and I want to rewrite the URL into something else (such as new-toy-search-xbox.html) Could someone please take me through the steps of how to do this? I've had a look at the Apache site but it's really confusing the way it's explained!
Technical SEO | | DanHill0