开发者

Redirect specific file request (at any location) to specific location

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开发者_JAVA技巧 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>


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]).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜