301 Redirecting pages with specific subpage in URL - .htaccess

I am woundering if there is a way to redirect all pages with specific parent page in URL
Basically I have a following duplicates of pages :
www.website/product-category-2/x-category
as well as
www.website/product-category/x-category
Is there a way to create a redirect that will push all the pages from product-category-2 to product-category?
So the redirect will look like this:
www.website/product-category-2/* -> www.website/product-category/*
Thank you for your help in advance

This should work
RewriteEngine on
RewriteRule ^product-category-2/(.*) /product-category/$1 [R=301,L]
It will redirect www.website/product-category-2/* to www.website/product-category/*

Related

How redirect comma separated url with htaccess?

There are 2 different URLs https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/ and https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/ but while SEO audit I found the wrong url and it is showing like https://maldivesresorts.com.au/luxury-resorts-study-vakarufalhi-maldives-resort/,https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/,here so I want to redirect the wrong url to another page.
So it should be redirect
to /hot-deals.
Here is my htaccess code but it doesn't seems working
RewriteEngine On
redirect /luxury-resorts-study-vakarufalhi-maldives-resort/,https://maldivesresorts.com.au/package/vakarufalhi-island-resort-all-meals-drinks/,here /hot-deals
This is how redirects work:
ref: https://www.semrush.com/blog/htaccess-redirect/
So you should be doing:
RewriteEngine On
redirect 301 /luxury-resorts-study-vakarufalhi-maldives-resort/ /hot-deals
redirect 301 /package/vakarufalhi-island-resort-all-meals-drinks/ /hot-deals
However, you look like you're redirecting folders rather than files so you should simply look at this question which your question appears to be a duplicate of.

How do I redirect a web URL using .htaccess

I want to redirect users who enter this website URL:
http://www.myWebsite.com/bananas
to:
http://www.myWebsite.com/fruits/bananas
I cant test it because I'm sending this to somebody.
I have these but I don't know for sure which one works:
RedirectMatch 301 http://www.myWebsite.com/bananas(.*) http://www.myWebsite.com/food/bananas $1
Options +FollowSymlinks
RewriteEngine on
rewriterule ^bananas(.*)$ http://www.myWebsite.com/food/bananas $1 [r=301,nc]
Please specify if you want to redirect or rewrite. The rules you are using serve different purposes and you used both in your example.
Redirect: Actually load a different site when entering the url (end up at url and content of /fruits/bananas)
Rewrite: Url stays the same but server provides rewritten content (url stays at /bananas, but show /fruits/bananas content)
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Also it is not clear if you only want one single directory to be redirected or all files that are contained in that directory.
Checkout this as a guide: http://www.htaccessredirect.net/
I believe you are looking for
Redirect 301 /bananas http://www.myWebsite.com/fruits/bananas
The HTTP 301 stands for Moved Permanently.
I haven't tested it, though.

.htaccess Redirect 301 Issue

I am having an htaccess issue that I cannot seem to figure out.
On my site I have several pages that have /wiget/ in the url.
.com/wiget/
.com/wigeta/
.com/wigeb/
.com/wigetc/
.com/shop/wigeta/
.com/shop/wigetb/
In my htaccess file I am using the following:
Redirect 301 /wiget/ http://www.site.com/content/wiget/
Redirect 301 /wigeta/ http://www.site.com/content/wigeta/
Redirect 301 /wigetb/ http://www.site.com/content/wigetb/
Etc.
What is happening, is that every URL with /wiget/ /wigeta/ /wigetb/ in it is getting redirected incorrectly. For example, these urls:
.com/shop/wiget/ is being sent to .com/shop/content/wiget/
.com/shop/wigeta/ is being sent to .com/shop/content/wigeta/
.com/shop/wigetb/ is being sent to .com/shop/content/wigetb/
What I want is only pages that have .com/wiget/ or .com/wigeta/ or .com/wigetb/ to be redirected to their .com/content/wiget{x}/ page
I am a rookie at htaccess and I cannot drum up the solution.
So basically you want to specify that your url have to start with /wiget/
RewriteRule ^/wiget/ /content/wiget/ [L,R=301]

.htaccess redirects - updated site (301 appropriate?)

I've run into a problem updating my site, the google search results show up links to the old page which are 404's now, some of them even containing deprecated content.
My question is about the use of 301's. The old page had deeply nested pages like the example below:
www.site.com/category/subjects/subject_b.html
It shows up in google with a very specific description of 'subject_b', which is not optimal for my purposes.
The new layout I've been working on means that content that was once under '/category/subjects/subject_b' is now found in a single page (www.site.com/subjects.html), along with the hypothetical subject_a & subject_c.
Would I be wrong redirecting the old pages like this?
redirect http://www.site.com/category/subjects/subject_a.html http://www.site.com/subjects.html
redirect http://www.site.com/category/subjects/subject_b.html http://www.site.com/subjects.html
redirect http://www.site.com/category/subjects/subject_c.html http://www.site.com/subjects.html
Also, how would I deal with pages that have google descriptions with content which is not on the new equavilient page?
I'd be happy if anyone could shed some light on this for me, or point me in a right direction as to where I can read more about it!
Would I be wrong redirecting the old pages like this?
You'd remove the http://www.site.com part. This should suffice:
Redirect 301 /category/subjects/subject_a.html /subjects.html
Redirect 301 /category/subjects/subject_b.html /subjects.html
Redirect 301 /category/subjects/subject_c.html /subjects.html
Or even:
RedirectMatch 301 ^/category/subjects/subject(.*) /subjects.html
to cover for all 3.
If you have multiple domains all pointing to the same document root and you actually need to match the path for a specific domain, you can use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site.com$ [NC]
RewriteRule ^/?category/subjects/subject(.*) /subjects.html [L,R=301]

complex htaccess rewrite

Before using word press for our new website we were using following urls...
http://www.domain.com/web-services
http://www.domain.com/seo-services (about 100 urls)
Now new url would be
http://www.domain.com/np/web-services
So we would like to 301 redirect all old pages to new pages, we could simple use following htaccess code...
Redirect 301 /web-services http://www.domain.com/np/web-services
But that would make htaccess file too large, so is there any way to redirect all pages to new pages.
thanks.
Enable mod_rewrite on your apache server, then put this inside your .htaccess file:
RewriteEngine On
RewriteRule ^/web-services/(.*)$ /np/web-services/$1 [R=301,L]
RewriteRule ^/seo-services/(.*)$ /np/web-services/$1 [R=301,L]
Any url starting with /web-services or /seo-services will be redirected to /np/web-services.
Or alternatively, you can use mod_alias' RedirectMatch:
RedirectMatch 301 ^/([^\-]+)-([^/]+)/?(.*)?$ /np/$1-$2/$3
So any request that starts with /web-services/ will get redirected with a /np appended to the front:
http://www.example.com/web-services/test1 -> http://www.example.com/np/web-services/test1
http://www.example.com/web-services/test/test2 -> http://www.example.com/np/web-services/test/test2
And the same with seo-services or anything with XXX-XXX.
EDIT:
if i try RedirectMatch 301 ^/([^\-]+)-([^/]+)-([^/]+) /np/$1-$2-$3/ its thorwing redirection error
Try:
RedirectMatch 301 ^/([^/\-]+)-([^/\-]+)-([^/]+) /np/$1-$2-$3/
Because /np/ is being matched against ^/([^\-]+)
You can rewite your domin like as if your domin was open with abc.com then you can permanently redirect it with www.abc.com. By doing this you can make sure that when google spider visit on your site then it can easily find your site. It also helps to increase more traffic on your site. If you have a busieness website then you can use SEO service from a company in Los Angeles going through reviews of best SEO Company in Chicago. Because these are helps to always push up your business growth towards top. Origin : http://www.bestseocompanyreviewss.com.

Resources