开发者

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

开发者 https://www.devze.com 2022-12-08 09:40 出处:网络
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:

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

精彩评论

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