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
-
URL ASCII Characters Issue
Hi guys; Is there any different between URL whit capital ASCII code and URL with small ASCII Code? For example I have 2 URLS for one page like this: 1- 332-%D8%AA%D8%AD%D8%B5%DB%8C%D9%84-%D8%AF%D8%B1-%DA%A9%D8%A7%D9%86%D8%A7%D8%AF%D8%A7.html 2- 332-%d8%aa%d8%ad%d8%b5%db%8c%d9%84-%d8%af%d8%b1-%da%a9%d8%a7%d9%86%d8%a7%d8%af%d8%a7.html both of them point to same page but no 1 is non SSL and no 2 is ssl version! and whole pges of site forces to https
Technical SEO | | seoiransite0 -
I have a Category and Tag In My Blogs
I have use category and Tags in my blogs. Now i have an problem with blog URL and Tags URL. My blog URLs is also show in Tags page and both the content is same. For Example: My Blog URL is: https://www.example.com/advice-how-to-do-batting And Tag Page URL is : https://www.example.com/advice-batting in that - https://www.example.com/advice-how-to-do-batting The URLs contain same content. No should i write two different meta title and description for above two URLs pages. As there might more blog added under Tags pages with different topics and title. Request on Thought Please.
Technical SEO | | ProcessSEO0 -
Should We Index These Category Pages?
Currently we have marked category pages like http://www.yournextshoes.com/celebrities/kim-kardashian/ as follow/noindex as they essentially do not include any original content. On the other hand, for someone searching for Kim Kardashian shoes, it's a highly relevant page as we provide links to all the Kim Kardashian shoe sightings that we have covered. Should we index the category pages or leave them unindexed?
Technical SEO | | Jantaro0 -
301 by category rather than page?
Hi Guys It is possible (and best practice) to 301 a category as a whole rather than every page within the category. I was asked this by a developer the other day, and it was something I'd not considered before as I've always done it by page. It seems there's some wordpress plugins out there that do it. Thanks in advance.
Technical SEO | | PerchDigital0 -
Penalty for many domains pointing to the same URL?
I've searched around on the Google forums, and other sources (including the Q&A!), but haven't seen a solid answer on this one. I've recently discovered that throughout the years we've had several hundred domains pointed to our homepage. These are our domains and are related to our niche. I believe they were pointed for the purposes of attracting type-in traffic. Before last month I knew at least some existed, but I didn't realize the extent until last week. I know there isn't any positive SEO effect to doing this (except perhaps if any of the domains have links to them, and a few do), but is there any negative SEO effect? I realize that there are legitimate redirects for type-in traffic, like misspellings and such, but most of these are just exact-match-domains. It just screams unnatural to me, but perhaps I'm just a little paranoid. 🙂
Technical SEO | | tncomseo0 -
Htaccess rewrites
We’re using wordpress, and we have the following in the .htaccess: BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] END WordPress We have a URL like http://subdomain.example.com/select-a-card/?q=fuel, and I want to rewrite it so that it becomes http://subdomain.example.com/fuel-card/ What do I need to add to the htaccess to do this?? Thanks,
Technical SEO | | AndrewAkesson0 -
Subdomain CMS or unique URL
I own a company for teams Ex myteams.com . A team registers and they get a site at team1.myteams.com. Content on each sub team site is mostly unique and I have several back links on each to the main site myteams.com. I also provide them with a unique URl team1.com will show team1.myteams.com. So couple questions As far as SEO should i be pushing the team1.com url or team1.myteams.com url? Is a link from team1.com or team1.myteams.com better for my site, their site or both How many back links should the sub sites have? Thanks
Technical SEO | | MichaelRyan220 -
Negative url name?
I have a new client who has the letters "BB" at the start of his url name, bbzautorepair.com. He was told by someone at Google Adwords that the letters "BB" in his url name could hurt him with Google rankings. Reason being that Google red flags anything or website to do with firearms, guns and ammunition. He was told that the letters "BB" could be mistaken or red flagged for "BB Gun". Seems a bit far fetched. Has anyone every heard of such a thing? Thanks
Technical SEO | | fun52dig
Gary Downey0