.htaccess Redirect 301 Issue - .htaccess

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]

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.

301 redirect in htaccess doesn't work. What am I doing wrong?

I've made an htaccess file, but several testers tell me it's not right.
Domain B is going offline and I want to redirect all the pages to new pages on domain A.
This is the code:
redirect 301 / https://domain-A.com/
redirect 301 /page-1/domain-B/ https://domain-A.com/page-1/
redirect 301 /page-2/domain-B/ https://domain-A.com/page-2/
redirect 301 / https://domain-A.com/
redirect 301 /page-1/domain-B/ https://domain-A.com/page-1/
redirect 301 /page-2/domain-B/ https://domain-A.com/page-2/
Your rules are in the wrong order. The Redirect directive is prefix-matching. The first rule redirects everything (and preserves the URL-path). The second and third rules are never processed. (What exactly is the "tester" reporting? Is this a thrid party tool or a real "tester" person?)
If you request /page-1/domain-B/ you will see that you are not redirected as intended. (You are redirected to https://domain-A.com/page-1/domain-B/, not https://domain-A.com/page-1/ as would seem to be the intention.)
You need to reverse the order of these rules. The most specific needs to be first.
For example:
Redirect 301 /page-1/domain-B/ https://domain-A.com/page-1/
Redirect 301 /page-2/domain-B/ https://domain-A.com/page-2/
Redirect 301 / https://domain-A.com/
You will need to clear your browser cache before testing since the erroneous 301s will have been cached by the browser. Test first with 302 redirects to avoid caching issues.
/page-1/domain-B/
And /domain-B/ is actually in the URL-path?

301 redirect from one domain to another but only for specific pages

We are rebuilding a website for a client from ASP to WordPress. This website will have a different domain, url structure, and file extension. I am only just getting my head around htaccess 301 redirects, and I know enough that I can't do the following:
Redirect 301 http://www.site1.com/about_us.asp https://site2.com/about/
Redirect 301 http://www.site1.com/art-specs/ https://site2.com/specs/
Redirect 301 http://www.site1.com/page/product1/ https://site2.com/product1/
There are about 12 links in total that need to be redirected, and I want to make sure that it is done right the first time as a client's SEO rankings are on the line.
Is there a variation of the above format that I could use? Or a rewrite rule that needs to be done first? Any help (and explanations) would be greatly appreciated!
After looking more into it, I realised that the htaccess file shouldn't need anything other than relative access to the original domain.
i.e. You shouldn't need to declare: http://www.site1.com/about_us.asp since the server and domain should be configured in such a way that /about_us.asp means the same thing.
So the correct answer would be to:
[1] Configure the server (in my case cPanel) by having the original domain added as an addon domain (e.g http://www.site1.com/).
[2] In the htaccess file I would add each of the 301 redirects to the htaccess file:
Redirect 301 /about_us.asp https://site2.com/about/
Redirect 301 /art-specs/ https://site2.com/specs/
Redirect 301 /page/product1/ https://site2.com/product1/
...for each redirect
[3] And finally, adding the following to the bottom of the htaccess file will catch everything else and redirect them to the home page:
RedirectMatch 301 .* https://site2.com

htaccess redirect to another domain - specific pages then remaining to go to homepage

I am in the process of redirecting an old site to another domain. Using htaccess I have listed around 40-50 specific pages to be re-directed to it's equivalent on the new domain i.e:
redirect 301 /delivery.php http://www.newdomain.com/delivery/
redirect 301 /contact.php http://www.newdomain.com/contact-us/
redirect 301 /about.php http://www.newdomain.com/about/
redirect 301 /stores/finder.php http://www.newdomain.com/branch-finder/
...
I then have probably around 600-700 other links where i don't need them to go to a specific page, just the new domains homepage. Is there a way I can have a 'and all other pages go to homepage' line or command to just go to http://www.newdomain.com? Otherwise I will have to manually type and enter each one
Is there a way I can have a 'and all other pages go to homepage' line
Yes sure you can have this rule as your last rule:
RedirectMatch 301 ^/.+ http://www.newdomain.com/

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