php htaccess 重写库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4844069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
htaccess RewriteBase
提问by Kit
I have two directories in my root: /dev
and /live
.
我的根目录中有两个目录:/dev
和/live
.
All content inside these directories have relative paths such as /css/style.css
or /js/home.js
.
这些目录中的所有内容都有相对路径,例如/css/style.css
或/js/home.js
。
I want to be able change the root directory using htaccess so that the relative paths would become /live/css/style.css
etc or /dev/css/style.css
depending on which version of the site I was using.
我希望能够使用 htaccess 更改根目录,以便相对路径变为/live/css/style.css
etc 或/dev/css/style.css
取决于我使用的站点版本。
I have tried using the following code in .htaccess located inside the /live
directory:
我尝试在位于/live
目录内的 .htaccess 中使用以下代码:
RewriteEngine on
RewriteBase /live/
I have also tried using RewriteBase /public_html/live/
.
我也试过使用RewriteBase /public_html/live/
.
But, the content paths are still http://domain.com/css/style.css
rather than http://domain.com/live/css/style.css
when I view the site.
但是,内容路径仍然是,http://domain.com/css/style.css
而不是http://domain.com/live/css/style.css
我查看网站时。
Has anyone any ideas?
有没有人有任何想法?
Thank you.
谢谢你。
EDIT>> Sorry I should explain that my root htaccess has the following rules pointing towards the two directories:
编辑>> 抱歉,我应该解释一下,我的根 htaccess 具有以下指向两个目录的规则:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^((www\.)?([a-z]+)\.)domain\.com [NC]
RewriteRule ^((www\.)?([a-z]+)\.)domain\.us$ /live/index.php?tag=%3 [L,P]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^dev.((www\.)?([a-z]+)\.)domain\.com [NC]
RewriteRule ^((www\.)?([a-z]+)\.)domain\.us$ /live/index.php?tag=%3 [L,P]
回答by outis
RewriteBase
lets you fix issues with how URLs get translated to file paths and back again. It's not for what you're using it for. Use a standard RewriteRule
RewriteBase
可让您解决 URL 如何转换为文件路径并再次返回的问题。这不是为了你使用它的目的。使用标准RewriteRule
RewriteCond %{REQUEST_URI} !^/live
RewriteRule ^(/?)(.*) /live/