Patan
Patan

Reputation: 17893

Exact Url match in apache redirect

I have a rewrite that needs be matched like below.

/test          ---No Match and no redirect
/test/         ---No Match and no redirect
/test/*        --Match and redirect. It should match only for this.

I have written a redirect rule that is matching for above all ocuurances.

RewriteRule ^/test/(.+)$ http://test.se/abcd/$1 [NC,R=301,L]

Please suggest that the above rule matches only for /test/anytext.

Upvotes: 1

Views: 3057

Answers (1)

Jon Lin
Jon Lin

Reputation: 143916

The rule you have is what you want, except since it's in an htaccess file (I assume), you need to get rid of that leading slash:

RewriteRule ^test/(.+)$ http://test.se/abcd/$1 [NC,R=301,L]

And make sure you have mod_rewrite loaded and the rewrite engine turned on:

RewriteEngine On

Upvotes: 1

Related Questions