How redirect comma separated url with htaccess? - .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.

Related

Rewrite Rule For Base Directory

So I'm trying to rewrite the following example. Took a look around but couldn't find the correct post that matched this scenario.
Here is a list of layout for old pages:
www.url.com/directory
www.url.com/directory/page1.html
www.url.com/directory/page2.php
I'm trying to rewrite the following way through htaccess:
Redirect 301 /directory /newdirectory
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
However, the first rewrite rule is interfering with old subpages in that path. So for example, using the above rewrite rules, going to:
www.url.com/directory/page1.html
Points the user to:
www.url.com/newdirectory/page1.html
When it should be pointing user to the slug without the original filename extension:
www.url.com/newdirectory/page1
The only way around this that I've been able to manage is to leave out the www.url.com/newdirectory/page1.html rule entirely. But there are a bunch of links pointing to that base path, so I'd like to redirect that.
Any help would be greatly appreciated. Thanks in advance for the time and help.
url-rewriting redirect rewrite-rules
You need to place the rule for the base directory after the ones for the subpages :
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
Redirect 301 /directory /newdirectory

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.

301 permanent redirect not working in htaccess

we are facing urls like "http://domain.com/p/post-content/%3Ca%20href=", these urls generate 404 errors, when we have tried to redirect something like that
Redirect 301 /p/post-title/<a href= /p/post-title/
But its not working, please anybody let me know, how to redirect url like this
The extra space is messing up the statement, apache will think there are too many arguments. Try:
Redirect 301 "/p/post-title/<a href=" /p/post-title/

.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]

Resources