301 redirects for some of the urls not working

Viewed 52

We have wrote the 301 rewrite rules in web version as below and it is working fine

RewriteRule ^staff-benefit-solutions https://www.sample.com/engage-your-employees/ [R=301,L,QSA]
RewriteRule ^corporate-benefits https://www.sample.com/engage-your-employees/ [R=301,L,QSA]

Below are the 301 rewrite rules for mobile version which i tried as below and its not redirecting


RewriteRule ^m/staff-benefit-solutions https://www.sample.com/engage-your-employees/  [R=301,L,QSA]
RewriteRule ^m/corporate-benefits https://www.sample.com/engage-your-employees/ [R=301,L,QSA]

In mobile my full urls will come something like this below www.yyy.com/m/staff-benefit-solutions when we open in the mobile browser. This should redirect to https://www.sample.com/engage-your-employees/ . Can someone help on this please

1 Answers

The question is, in which context do you use the RewriteRule - in VirtualHost or in Directory context? I assume in directory context, because you tagged .htaccess.

Apache Module mod_rewrite says:

In per-directory context (Directory and .htaccess), the Pattern is matched against only a partial path, for example a request of "/app1/index.html" may result in comparison against "app1/index.html" or "index.html" depending on where the RewriteRule is defined.

So you need to define your rewrite in the .htaccess under your root directory and not under your m directory.

Related