0

my htaccess file look like

Options +FollowSymLinks

RewriteEngine On

RewriteRule  ^(.*)companies/partners-in-(.*)$  /companies/country.php?country=$2  [R=301,L]

Expected result was http://example.com/companies/partners-in-USA ... But instead of that it redirect to http://example.com/companies/country.php?country=USA

What I am missing in my htaccess file

syam
  • 88
  • 2
  • 9
  • ^(.*)companies\/sap-partners-in-(.*)$ – syam Jan 18 '18 at 07:56
  • 2
    Well, you have a `[R]` redirect flag there. So why isn't it what you expected? What did you originally want to accomplish? (Sure you understand how [mod_rewrite works](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) - it's more about mapping, not rewriting). – mario Jan 18 '18 at 08:00
  • 1
    Your rule is redirecting the request instead of rewriting it because of the R flag . Simply remove it and you will be fine. – Amit Verma Jan 18 '18 at 08:12
  • Thanks. R flag was the issue. Now it working perfectly – syam Jan 18 '18 at 12:17

1 Answers1

0

The "/companies/country.php?country=$2" bit in your rewrite rule is telling Apache where to redirect to, so if you want to redirect to "/partners-in-xxx" you'll need to change that bit to "/partners-in-$2".

rangfu
  • 774
  • 5
  • 14