0

So here's what I have.

  • www.website.com/foo (pretty URL to use on marketing pieces)
  • www.website.com/foobar (URL that actually exists on site)

I can get www.website.com/foo working perfectly with this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /foo [NC]
RewriteRule ^ http://www.website.com/redirected/url-goes-here/   [L,R=301]

But that makes the www.website.com/foobar URL go there as well.

I'm sure this is a regex issue and I just don't know the correct symbol to get things working properly, but how can I make /foo redirect properly without effecting /foobar ?

Thanks.

cschneider27
  • 299
  • 1
  • 4
  • 13

2 Answers2

1

Try this instead:

RewriteCond %{REQUEST_URI} ^/foo$ [NC]
RewriteRule ^ http://www.website.com/redirected/url-goes-here/   [L,R=301]

REQUEST_URI will get rid of the extra request headers that THE_REQUEST has. Then you can match the beginning and end of the requested URL with ^ and $.

Steven V
  • 16,357
  • 3
  • 63
  • 76
0

You don't need the RewriteCond. Just be specific with the RewriteRule pattern

RewriteRule ^foo$ http://www.website.com/redirected/url-goes-here/   [L,R]

See more about regular expression.

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198