.htaccess:如果调用了特定目录,则重写整个URL [英] .htaccess: Rewrite entire URL if specific directory is called
问题描述
我在那儿占了90%,但我想念一些明显的东西.我正在做一个站点的本地Web开发.我正在工作的网站的媒体目录很大-超过15 GB.我不想为了在我的本地环境中查看此映像而复制并定期进行更新,而是希望将所有请求重定向到media/目录中,再返回到生产站点.
I'm 90% there but I'm missing something obvious. I am doing local web development of a site. The media directory of the site I'm working on is huge - upwards of 15 GB. Instead of copying that and having to update it periodically just for the sake of viewing this images in my local environment, I want to redirect any requests into the media/ directory back to the production site.
从这里...
localhost:8888/sitefolder/media/*
对此...
www.productionserver.com/media/*
到目前为止,这是我所拥有的,但是我认为我需要使用重写条件"指令:
This is what I have so far but I think I need to use the Rewrite Condition directive:
RewriteRule ^media/(.*)$ http://www.productionserver.com/media/$1[QSA,R=301,L]
谢谢.
推荐答案
某些语法问题,您需要在$1
后加一个空格,并且不需要QSA:
Some syntax issues, you need a space after $1
and QSA isn't needed:
RewriteEngine On
RewriteRule ^media/(.*)$ http://www.productionserver.com/media/$1 [NC,R=301,L]
- 确保将其放置在
sitefolder/.htaccess
中
- 确保这是
RewriteEngine On
之后的第一条规则
- Make sure this is placed in
sitefolder/.htaccess
- Make sure this is first rule after
RewriteEngine On
这篇关于.htaccess:如果调用了特定目录,则重写整个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!