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

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.

Related

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

redirect certain pages to its equivalent in another domain, otherwise redirect to its homepage

I want to use htaccess to redirect certain pages to its equivalent in another domain, other pages redirect to homepage.
Like that:
http://old-domain.com/certain-page redirected to: http://new-domain.com/certain-page
http://old-domain.com/another-certain-page redirected to: http://new-domain.com/another-certain-page
Only these pages will be redirected, otherwise, pages have to be redirected to the new domain home page.
http://old-domain.com/non-certain-page redirected to: http://new-domain.com
This is my try:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^certain-page$ http://new-domain.com/certain-page [R=301,L]
RewriteRule ^another-certain-page$ http://new-domain.com/another-certain-page [R=301,L]
</IfModule>
But don't know how to exclude other pages.
Any help here?
Thanks in advance!
I'm not sure what you mean by
But don't know how to exclude other pages
But you are already excluding the pages when you create specific rules for them. This should work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#redirect specific pages
RewriteRule ^certain-page$ http://new-domain.com/certain-page [R=301,L]
RewriteRule ^another-certain-page$ http://new-domain.com/another-certain-page [R=301,L]
#Redirect everything else to homepage
RewriteRule ^(.*)$ http://new-domain.com/ [R=301,L]
</IfModule>
Let me know how this works for you. If you need to clear you cache before trying these new rules.
Another answer was mentioned here, thank to anubhava
With redirect without need to use Rewrite :
RedirectMatch 301 ^/.+ http://www.newdomain.com/
So, the answer can be also:
#Redirect specific pages
redirect 301 /certain-page http://new-domain.com/certain-page
redirect 301 /another-certain-page http://new-domain.com/another-certain-page
#Redirect everything else to homepage
RedirectMatch 301 ^/.+ http://new-domain.com

301 redirects - problems with dashes

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.

Remove query strings from HTTP response status code 301 url redirections

My .htaccess file contains Rewrite URLs and HTTP response status code 301 url redirections. When I test the redirections, it adds the query string values from the old url to the end of the redirected url. How can I stop this?
My htaccess looks like this.
Options +FollowSymlinks
Redirect 301 /old-site/tees~1-c/blue~123-p.html test.mydomain.com/tees~1-c/blue~123-p.html
Redirect 301 /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html
Redirect 301 /old-site/content/about.html test.mydomain.com/content/about.html
RewriteEngine on
RewriteRule ^(.+)~(.+)-c/(.+)~(.+)-p\.html?$ product.php?cde=$1&cid=$2&pde=$3&pid=$4 [QSA]
RewriteRule ^(.+)~(.+)-c\.html?$ category.php?cde=$1&cid=$2&ref=%3&srt=%4&sta=%5&ppa=%6 [QSA]
RewriteRule ^content/(.+)\.html?$ info.php?seo=$1&sta=%1 [QSA]
As stated at the mod_alias doc
If the client requests http://example.com/service/foo.txt, it will be
told to access http://foo2.example.com/service/foo.txt instead. This
includes requests with GET parameters, such as
http://example.com/service/foo.pl?q=23&a=42, it will be redirected to
http://foo2.example.com/service/foo.pl?q=23&a=42
You can change your Redirec 301 to Rewrite rules:
Instead of:
Redirect 301 /old-site/tees~1-c/blue~123-p.html test.mydomain.com/tees~1-c/blue~123-p.html
Redirect 301 /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html
Redirect 301 /old-site/content/about.html test.mydomain.com/content/about.html
Use:
RewriteRule /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html [L,R=301]
RewriteRule /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html [L,R=301]
RewriteRule /old-site/content/about.html test.mydomain.com/content/about.html [L,R=301]
If you don't include the QSA flag, NO query param is added to the rewrited url