views:

266

answers:

3
RewriteEngine on
RewriteRule ^/(dir1|dir2|dir3)/(.*)$ /targetfile.php [R,L]

http://www.somesite.com/dir1 -> http://www.somesite.com/targetfile.php
http://www.somesite.com/dir2 -> http://www.somesite.com/targetfile.php
http://www.somesite.com/dir3 -> http://www.somesite.com/targetfile.php

From what I've seen online, this should work. Unfortunately, it wont. Any insight?

+1  A: 

If you want to use this in a .htaccess file, remove the leading slash from the pattern. And to match only full path segments, you have to alter the expression a little bit.

So try this:

RewriteEngine on
RewriteRule ^(dir1|dir2|dir3)(/|$) targetfile.php [R,L]
Gumbo
+1  A: 

I don't believe the forward slashes are necessary, unless you want to restrict it to requiring the trailing slash after "dir1."

Try: RewriteRule ^(dir1|dir2|dir3)$ targetfile.php [QSA,L]

Brian D.
A: 

I think the problem is that the regular expression mandates a slash after the directory name (e.g. /dir1/), but in the example the last slash is omitted (http://www.somesite.com/dir1 does not have trailing slash).

I think you could try just with

RewriteRule ^/(dir[1-3]) /targetfile.php [R,L]
antti.huima