Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
灵活的.htaccess文件,适用于本地和在线环境_.htaccess - Fatal编程技术网

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

灵活的.htaccess文件,适用于本地和在线环境,.htaccess,.htaccess,我有一个简单的Wordpress.htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] 我要搜索的是如何使.htaccess知道它在哪个环境中运行,从而相应地更改RewriteBase和RewriteRul

我有一个简单的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]
但不要让它发挥作用。第一条规则总是适用的

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

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

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

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

Wordpress解决这个问题的方法是使用Wordpress编写的编程语言生成它。我不明白你的评论?我只需要重写我的.htaccess以用于在线/本地。Wordpress initiale为其安装的环境创建.htaccess。我需要不同环境的不同规则。在服务器配置文件中,您可能使用了VirtualHost。对于RewriteRule,您可以添加条件RewriteCond%{HTTP_HOST}=192.168.0.1。对于RewriteBase,我不知道。我用你建议的RewriteCond%{HTTP_HOST}=192.168.0.100更新了我的问题,但它没有生效。我拼错了什么吗?我试了很多,结果出乎意料地简单:在RewriteCond%{REQUEST_FILENAME}上启动WordPress RewriteEngine-f RewriteCond%{REQUEST_FILENAME}-重写规则。index.php[L]END WordPress这对离线和在线都有效。