301 redirects - problems with dashes - apache

For some unknown reason some of my 301 redirects work fine and some don't I cannot for the life of me work out why.
These ones are fine:
# Permanent URL redirect
RewriteEngine on
Redirect 301 /uk http://www.mysite.co.uk
Redirect 301 /uk/about-us http://www.mysite.co.uk/about-us/
Redirect 301 /uk/privacy-policy http://www.mysite.co.uk/privacy-policy/
Redirect 301 /uk/withdrawal http://www.mysite.co.uk/withdrawal-consent/
Redirect 301 /uk/promotions http://www.mysite.co.uk/promotions/
These ones do not work:
Redirect 301 /uk/feedback-enquiries http://www.mysite.co.uk/feedback/
Redirect 301 /uk/success-stories http://www.mysite.co.uk/testimonials/
and I get these 2 URLs returned as 404s:
http://www.mysite.co.uk/feedback-enquiries
http://www.mysite.co.uk/success-stories
It's as if there's an issue with the hyphens/dashes..but only when the page name has actually changed and only when the original pages uses a hyphen.

Use below code(Replace each Url with concerning main/redirect url) - -
RewriteCond %{REQUEST_URI} ^/uk/feedback-enquiries$
RewriteRule .* http://www.mysite.co.uk/feedback/ [L,R=301]
All your url should work by this pattern, Let me know if still you face any issue.

Related

After 301 .htaccess redirect question mark in the URL with extra items

Thanks in advance for helping me. I am new here and also new to redirect rules. I have an issue after .htaccess 301 redirect I did on my website url's.
First, the URLs slugs were with "_" (underscore).
2nd, I change URL's structure from "_" to "-" (hyphen).
I now did .htaccess 301 redirects from old URL to the new URLs.
ISSUE: when I redirect the URL, and try to click my URL from google search it worked, but with extra slugs (?promo/sports_and_outdoors_coupons=23&hta&ext=) in the URLS.
Here is my .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)(\-(\d+))?([.]\w+|\/)?$ index.php?$1=$3&hta&ext=$4 [QSA,L]
Redirect 301 /promo/auto_parts-26 /promo/auto-parts-26
Redirect 301 /promo/bath__body-27 /promo/bath--body-27
Redirect 301 /promo/computers_and_electronics-8 /promo/computers-and-electronics-8
Redirect 301 /promo/health__wellness-13 /promo/health--wellness-13
Redirect 301 /promo/home_and_garden-14 /promo/home-and-garden-14
Redirect 301 /promo/musical_instruments-16 /promo/musical-instruments-16
Redirect 301 /promo/office_supplies-17 /promo/office-supplies-17
Redirect 301 /promo/party_supplies-18 /promo/party-supplies-18
After clicking url from google search, this is the permanlink on my website:
https://website.com/promo/auto-parts-26?promo/auto_parts_26=26&hta&ext=
I need quick fix, would you kindly help, what I am doing wrong.
thank you.
Main issue occurring from this part
RewriteRule ^(.*?)(\-(\d+))?([.]\w+|\/)?$ index.php?$1=$3&hta&ext=$4 [QSA,L]
I removed it, url redirect correctly, but page was not loading. url not found error.

.htacess redirect 301 doesn't work properly

I have issue to redirect 301 URLs,
I want to redirect from fr.example.com/fr to www.example.com/fr-ch
the rest of the URL doesnt have always same structure but htaccess redirect to same structure,
exemple:
RewriteCond %{HTTP_HOST} ^fr\. [NC]
Redirect 301 /fr https://www.example.com/fr-ch
Redirect 301 /fr/coffee/arabica-robusta https://www.example.com/fr-ch/ccc/arabica-robusta
what I get as result is redirect to
https://www.example.com/fr-ch/coffee/arabica-robusta
and not to
https://www.example.com/fr-ch/ccc/arabica-robusta
Am I missing something ??
You need to redirect EXACTLY /fr, so you need to add ^ in the beginning and $ at the end.
So this should work :
Redirect 301 ^/fr$ https://www.example.com/fr-ch

Alternative for bulk Redirect 301 in htaccess

I have some link redirects in htaccess in which every link should be added with /en after .com i.e.,
mydomain.com, mydomain.com/abc.html
to
mydomain.com/en, mydomain.com/en/abc.html
After some research i found that redirect 301 does it. But I think this is not perfect and permanent solution. In future if I add another URL, again I have to add it to htaccess. So can any one help me out in getting the perfect and permanent solution for this.
I have done this in my htaccess
Redirect 301 /about.html /en/about.html
Redirect 301 /contact-us.html /en/contact-us.html
Redirect 301 /index.html /en/index.html
Redirect 301 /locations.html /en/locations.html
You can use this single redirect rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^(?!en/)(.+\.html)$ /en/$1 [L,NC,NE,R=301]
(?!en/) is negative lookahead to assert that URI is not already starting with /en/.

.htaccess - redirect, if a specific url match

I need to redirect users to a new domain, but I need that in case a user visits a particular URL, then he/she needs to be redirected to another URL.
Let me clarify...
If the user visits http://oldexample.com/postvendita/ I need to redirect them to http://newexample.com/assistenza
Otherwise, for every other URL http://oldexample.com/* I need to redirect them to http://newexample.com/new-page
Here is my attempt:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)postvendita(.*)$ http://www.newexample.com/assistenza [L,R=301]
RewriteCond %{HTTP_HOST} !^oldexample\.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/new-page [R=301,L]
Now if I visit any of the old pages, I will be redirected to http://www.newexample.com/new-page, so the first rule doesn't work, how should I change it?
To handle this via .htaccess you'll want to match the first one and use a catch-all to redirect everything else:
RewriteEngine On
RewriteRule ^postvendita/?$ http://www.newexample.com/assistenza [R=301,L,NE]
RewriteRule .* http://www.newexample.com/new-page [R=301,L,NE]
A 301 redirect is a permanent redirect which passes between 90-99% of
link juice (ranking power) to the redirected page. 301 refers to the
HTTP status code for this type of redirect. In most instances, the 301
redirect is the best method for implementing redirects on a website.
More About Redirects
Alternatively, if you're not comfortable writing RewriteRules, you can use the following lines:
Redirect 301 /postvendita/ http://www.newexample.com/assistenza
Redirect 301 /postvendita http://www.newexample.com/assistenza
Redirect 301 / http://www.newexample.com/new-page
Or with RedirectMatch:
RedirectMatch 301 /postvendita/? http://www.newexample.com/assistenza
RedirectMatch 301 .* http://www.newexample.com/new-page
Common .htaccess Redirects

htaccess RewriteRule and Redirect 301 don't work

We're trying to set up 301 redirects to make sure Google uses the right category pages. We can't set up a canonical and a normal Redirect 301 /n.html https://website.com/n.html doesn't work either, it's just ignored. We're on Opencart 1.5.5.1. The issue is that the 301s are just ignored, they're not implemented at all both Redirect 301 and RewriteRule
# SEO URL Settings
RewriteEngine On
RewriteRule ^/refrigeration/Multidecks/fresh-meat-multidecks$ https://www.website.co.uk/Multidecks/fresh-meat-multidecks [R=301,L]
RewriteRule ^/fresh-meat-multidecks$ https://www.website.co.uk/Multidecks/fresh-meat-multidecks/ [R=301,L]
Like Anubhava said, the issue is the / after the ^