I have been searching around and I cant seem to find an exact answer to my problem. For this example i will use domain.com as my domain name.
I have htaccess rules in place to redirect pretty urls to actual pages within the web server. Just like this
RewriteEngine on
RewriteBase /
...
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(fr|en)/(a-propos|about-us)$ pages/about.php?lang=$1&%{QUERY_STRING}
RewriteRule ^(fr|en)/(a-propos|about-us)$ pages/about.php?lang=$1
As you can see, this basically loads the /pages/about.php file when accessing domain.com/en/about-us url. This works just as it should.
My issue comes from when someone is trying to access the url directly by going to domain.com/pages/about.php, i dont want that to be a possibility or to affect my SEO by basically saying there are 2 URLs for the same page. So i read that by doing something like the code below would work. BUT its actually just keeping the URL that was entered and not doing what i need it to.
RewriteCond %{THE_REQUEST} \s/about\.php\?lang=en\s [NC]
RewriteRule ^ /en/about-us? [R=301,L]
RewriteRule ^en/about-us$ /pages/about.php?lang=en [L]
Any help or clarification is greatly appreciated
EDIT
I have also tried this below, but it obviously just does an endless loop adding the lang to the query string.
RewriteCond %{REQUEST_URI} ^/pages/about.php [NC]
RewriteCond %{QUERY_STRING} ^lang=en
RewriteRule ^ en/about-us [R=301,L]
RewriteCond %{REQUEST_URI} ^/pages/about.php [NC]
RewriteCond %{QUERY_STRING} ^lang=fr
RewriteRule ^ fr/a-propos [R=301,L]
RewriteRule ^(fr|en)/(a-propos|about-us)$ pages/about.php?lang=$1&%{QUERY_STRING} [L]
RewriteRule ^(fr|en)/(a-propos|about-us)$ pages/about.php?lang=$1 [L]