mod_rewrite:两个网站,图像的相对链接。将图像 URL 请求重写到单个物理文件夹
/en/
文件夹中有一个网站A和一个网站B。所以:
网站 A:http://domain/
网站B:http://domain/en/
这两个网站都有 /images/
文件夹。
我希望对网站 B 的图像的任何请求都重定向到网站 A 的图像。换句话说:http://domain/en/images/*
→ http://domain/images/*
这就是我尝试做的:
RewriteEngine On
RewriteBase /
RewriteRule ^en/images/(.*)$ /images/$1
并且我尝试添加条件,例如RewriteCond %{REQUEST_FILENAME} !-f
。它不起作用。
.htacces 文件的内容应该是什么?我应该将其放在哪个物理文件夹中?
There is a website A and a website B in /en/
folder. So:
Website A: http://domain/
Website B: http://domain/en/
Both of the websites have /images/
folder.
I want any requests to the images of the website B, to be redirected to the images of the website A. In other words:http://domain/en/images/*
→ http://domain/images/*
This is what I tried to do:
RewriteEngine On
RewriteBase /
RewriteRule ^en/images/(.*)$ /images/$1
And I have tried adding conditions like RewriteCond %{REQUEST_FILENAME} !-f
. It didn't work.
What should be the contents of the .htacces file and in what physical folder I should put it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要外部重定向(实际上将浏览器发送到新 URL):
否则,
这应该位于网站的
块中。如果且仅当您无权访问虚拟主机配置,并且需要内部重定向,则可以将其放入
/var/www/document_root/en/images/ 中。 htaccess
:If you want an external redirect (actually send the browser to the new URL):
Otherwise,
This should go in the
<VirtualHost>
block for the website.If and only if you do not have access to the virtual host configuration, and if you want an internal redirect, you can put this in
/var/www/document_root/en/images/.htaccess
:如果您将其放在文档根目录中,它应该可以工作,但如果您想重定向浏览器,则需要在 RewriteRule 末尾添加一个
[R]
,并且为了安全起见,也是一个[L]
。要使用 301(永久)重定向,请将
R
更改为R=301
。If you put that in your document root, it should work, but if you want to redirect the browser, you need a
[R]
at the end of your RewriteRule, and to be safe, an[L]
, too.To redirect with a 301 (permanent), change
R
toR=301
.