views:

69

answers:

1

I have a specific file, let's call it 'myfile.abc', that I need to have redirected to a specific location, no matter what location it's requested from. For instance:

/folder1/myfile.abc
/folder2/myfile.abc
/folder3/myfile.abc

I need all the above to be redirected to (as an example):

/myfolder/myfile.abc

How do I achieve that within the .htaccess file?

In response to Gumbo's answer, I now have the following in my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !=myfolder
RewriteRule ^([^/]+)/myfile.abc$ myfolder/myfile.abc [L]
RewriteRule . /index.php [L]
</IfModule>
+1  A: 

Try this:

RewriteEngine on
RewriteCond $1 !=myfolder
RewriteRule ^([^/]+)/myfile\.abc$ myfolder/myfile.abc [L]

And if you want an external redirect, add the R flag with an optional redirect status code ([L,R]/[L,R=301]).

Gumbo
Thank you for your answer - it works great on a page that requests this file, but I get 500 error on other pages. It's on a WordPress site, so the .htaccess contains the WP redirect code too - I've added what I have in the .htaccess file to the main question. Could you please advise on what the issue is, thanks.
BrynJ
No matter, I've gotten it working by shuffling the rules around a bit.
BrynJ