灵活的.htaccess文件,适用于本地和在线环境

时间:2014-08-11 09:25:05

标签: .htaccess

我有一个简单的Wordpress .htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

我正在寻找的是如何让.htaccess知道它运行的环境,相应地更改RewriteBase和RewriteRule。

像(虚拟)

之类的东西
if HTTP_HOST == "192.168.0.1" RewriteBase /localfolder, RewriteRule . /local/index.php [L]
else (for all other domains assume online) RewriteBase /, RewriteRule . /index.php [L]

有没有办法实现这个目标?

我试过像

这样的东西
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} =192.168.0.100
RewriteBase /local/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /local/index.php [L]

但不要让它发挥作用。总是第一个规则是apllied

UPD:

这似乎是离线和在线的完美解决方案:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

1 个答案:

答案 0 :(得分:0)

这似乎是离线和在线的完美解决方案:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress