GVKun编程网logo

在.htaccess中设置环境变量,然后在PHP中检索它(php加入环境变量)

8

对于想了解在.htaccess中设置环境变量,然后在PHP中检索它的读者,本文将提供新的信息,我们将详细介绍php加入环境变量,并且为您提供关于apache环境.htaccess设置301跳转及常用.

对于想了解在.htaccess中设置环境变量,然后在PHP中检索它的读者,本文将提供新的信息,我们将详细介绍php加入环境变量,并且为您提供关于apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理、eshell 中设置环境变量、eshell中设置环境变量、htaccess-如何比较环境变量-检查2个环境变量是否相同的有价值信息。

本文目录一览:

在.htaccess中设置环境变量,然后在PHP中检索它(php加入环境变量)

在.htaccess中设置环境变量,然后在PHP中检索它(php加入环境变量)

我正在尝试在.htaccess文件中设置环境变量并在PHP中检索它。我在SO上浏览了许多其他线程,但是到目前为止我尝试过的所有操作都失败了。

我已经将此行添加到.htaccess文件中:

SetEnv SPECIAL_PATH /foo/bin

我尝试使用getenv()PHP函数检索此值:

<?php $specialPath = getenv(''SPECIAL_PATH''); ?>

我已经运行phpinfo()来查看可用环境变量的列表,SPECIAL_PATH不存在。我对为什么这不起作用感到困惑。

谢谢!

答案1

小编典典

假设您的配置具有带有.htaccess的AllowOverrides,则必须在Apache中启用mod_env才能使其正常工作。

apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理

apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理

apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理


无论是 Nginx,还是 Apache 都各自有优势,对于我们普通用户而言基本上也没有多大的区别。在虚拟主机环境中,基本上都是 Apache 环境。Apache 与 Nginx 两者区别之一就是伪静态的设置,前者则是在网站根目录设置.htaccess 文件,无论是伪静态,还是 301 跳转,甚至是防盗链和禁止某个 IP 的访问都可以很简单的设置。

Apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理

关于.htaccess 文件的设置和实际应用是相当广泛的,很多功能都可以利用这个小小的文件实现,只不过我们普通用户使用的并不多而已,比如我们使用最多的无非就是 WWW 或者非 WWW 301 跳转,顶多加上防盗链等功能,在这篇文章中就是.htaccess 文件的常见的用法。

第一、强制 www 域名 301 跳转

RewriteEngine on
RewriteCond %{HTTP_HOST} ^chinasoft\.com [NC]
RewriteRule ^(.*)$ https://www.chinasoft.com/$1 [L,R=301,NC]

我们将域名替换成自己的域名即可实现非 WWW 跳转到 WWW 域名。

第二、强制非 WWW 域名 301 跳转

RewriteEngine On
RewriteCond %{HTTP_HOST} !^chinasoft.com$ [NC]
RewriteRule ^(.*)$ http://chinasoft.com/$1 [L,R=301]

这里我们可以强制如果访问 www 域名前缀,会跳转到非 www 域名。

第三、强制 https 跳转地址

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.chinasoft.com/$1 [R,L]


同时满足强制跳转 https 和 www 的示例

# 强制跳转 https 和 www
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.io
RewriteRule ^(.*)$ https://www.chinasoft.io/$1 [R,L]

如何我们网站采用 SSL 证书,则一般需要强制跳转 https 路径,这里需要添加强制 80 端口的跳转。

第四、阻止无用的蜘蛛爬取

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (^$|FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms) [NC]
RewriteRule ^(.*)$ - [F]

第五、强制 / 斜杠结尾路径

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

第六、取消 / 斜杠结尾

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]

第七、将 A 页面 301 跳转到 B 页面

Redirect 301 /a.html https://www.chinasoft.com/b.html

第八、阻止某个 IP 访问

Order deny,allow
Allow from all
Deny from xxx.xxx.xxx.xxx

第九、禁止图片盗链

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?chinasoft.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|bmp)$ - [NC,F,L]

第十、禁止被其他网页套用

SetEnvIf Request_URI "/starry-night" allow_framing=true
Header set X-Frame-Options SAMEORIGIN env=!allow_framing

第十一、全部重定向到 B 网站

RewriteEngine on
RewriteRule ^(.*)$ http://www.chinasoft.com/$1 [R=301,L]

如果我们更换域名或者希望域名流量全部导入新网站,这里可以全部跳转。

第十二、去掉默认首页 index.html

# 去掉 index.html
RewriteCond %{REQUEST_URI} ^(/index\.html)$ [NC]
RewriteRule ^(.*) / [R=301,L]

RewriteCond %{REQUEST_URI} !^(/index\.html)$ [NC]
RewriteCond %{REQUEST_URI} (/index\.html)$ [NC]
RewriteRule (.+)/index\.html /$1/ [R=301,L]

第十三、常用状态码全局跳转

ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 405 /405.html
ErrorDocument 500 /500.html
ErrorDocument 503 /503.html

ErrorDocument 这里填 403,404 等错误信息调整页面,用来访问出现 404 页面等情况时的错误页面展示

总结,平时常用和不常用的.htaccess 伪静态、301、防盗链以及等设置功能。如果需要更多强大的 htaccess 功能则需要阅读官方文档。


Apache Rewrite 规则简介:
Rewirte 主要的功能就是实现 URL 的跳转,它的正则表达式是基于 Perl 语言。可基于服务器级的 (httpd.conf) 和目录级的 (.htaccess) 两种方式。如果要想用到 rewrite 模块,必须先安装或加载 rewrite 模块。方法有两种一种是编译 apache 的时候就直接安装 rewrite 模块,别一种是编译 apache 时以 DSO 模式安装 apache, 然后再利用源码和 apxs 来安装 rewrite 模块。
基于服务器级的 (httpd.conf) 有两种方法,一种是在 httpd.conf 的全局下直接利用 RewriteEngine on 来打开 rewrite 功能;另一种是在局部里利用 RewriteEngine on 来打开 rewrite 功能,下面将会举例说明,需要注意的是,必须在每个 virtualhost 里用 RewriteEngine on 来打开 rewrite 功能。否则 virtualhost 里没有 RewriteEngine on 它里面的规则也不会生效。
基于目录级的 (.htaccess), 要注意一点那就是必须打开此目录的 FollowSymLinks 属性且在.htaccess 里要声明 RewriteEngine on。

Apache mod_rewrite 规则重写的标志一览
1) R [=code](force redirect) 强制外部重定向
强制在替代字符串加上 http://thishost [:thisport]/ 前缀重定向到外部的 URL. 如果 code 不指定,将用缺省的 302 HTTP 状态码。

2) F (force URL to be forbidden) 禁用 URL, 返回 403HTTP 状态码。

3) G (force URL to be gone) 强制 URL 为 GONE,返回 410HTTP 状态码。

4) P (force proxy) 强制使用代理转发。

5) L (last rule) 表明当前规则是最后一条规则,停止分析以后规则的重写。

6) N (next round) 重新从第一条规则开始运行重写过程。

7) C (chained with next rule) 与下一条规则关联
如果规则匹配则正常处理,该标志无效,如果不匹配,那么下面所有关联的规则都跳过。

8) T=MIME-type (force MIME type) 强制 MIME 类型

9) NS (used only if no internal sub-request) 只用于不是内部子请求

10) NC (no case) 不区分大小写

11) QSA (query string append) 追加请求字符串

12) NE (no URI escaping of output) 不在输出转义特殊字符
例如:RewriteRule /foo/(.*) /bar?arg=P1%3d$1 [R,NE] 将能正确的将 /foo/zoo 转换成 /bar?arg=P1=zoo

13) PT (pass through to next handler) 传递给下一个处理
例如:
RewriteRule ^/abc (.*) /def$1 [PT] # 将会交给 /def 规则处理
Alias /def /ghi
14) S=num (skip next rule (s)) 跳过 num 条规则
15) E=VAR:VAL (set environment variable) 设置环境变量

301 跳转的实现是通过编辑网站主目录下的 301jump 文件来实现的。
本地保留一份与服务器上一样的文件(301jump),需要设置 301 跳转的时候可以通过编辑这个文件(添加需要的 301 跳转或者去除不需要的 301 跳转),然后通过 FTP 上传到网站目录下面 (test 的服务器上),覆盖掉以前的文件。
然后通过 test. 域名.com 的地址访问,测试 301 跳转是否生效。生效后同步到远程服务器即可。
301jump 文件的格式如下:

RewriteEngine on
RewriteRule  ^a.html  /b.html  [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
……………………………………..

下面介绍介绍跳转规则
第一行 RewriteEngine on 是开启跳转功能的配置

第二行开始
如:RewriteRule XXXXXXX XXXXXXX [R=301,L] 格式的是跳转
每一行表示一个跳转

我们的设置只要在文件末尾添加要设置的跳转,或者删掉要去除的跳转

跳转情况说明:(说明均是以 chinasoft.com 站点下的 301jump 编写为例)

情况一
http://www.chinasoft.com/a.html   跳转到 http://www.chinasoft.com/b.html
让站点下面的一个页面跳转到另一个页面

写法如下:
RewriteRule  ^a.html  /b.html  [R=301,L]

情况二
http://www.chinasoft.com/a.html   跳转到 http://www.chinasoft.com/abc/b.html
让站点下面的一个页面跳转到非同级目录的另一个页面

写法如下:
RewriteRule  ^a.html  /abc/b.html  [R=301,L]

http://www.chinasoft.com/abc/a.html   跳转到 http://www.chinasoft.com/b.html
让站点下面的一个页面跳转到非同级目录的另一个页面

写法如下:
RewriteRule  ^abc/a.html  /b.html  [R=301,L]

情况三
http://www.chinasoft.com/word/index.html  跳转到 http://www.chinasoft.com/word/
让 chinasoft.com 站点下的 /word/index.html 文件夹的链接重新定向到 /word/ 目录,seo 优化

写法如下:
RewriteRule  ^word/index.html /word/   [R=301,L]

情况四
http://www.chinasoft.com/word/   跳转到 http://www.chinasoft.com/sentence/
让 chinasoft.com 站点下的 /word/ 文件夹的链接重新定向到 /sentence/ 下面,包含下层路径
例如:http://www.chinasoft.com/word/a.php
会被定向到 http://www.chinasoft.com/sentence/a.php
写法如下:
RewriteRule  ^word/(.*)$  /sentence/$1  [R=301,L]

情况五
http://www.chinasoft.com/word/   跳转到 http://www.chinasoft.com
让 chinasoft.com 站点下的 /word 文件夹的链接重新定向到 根目录 下面,包含下层路径
例如:http://www.chinasoft.com/word/a.php
会被定向到 http://www.chinasoft.com/a.php
写法如下:
RewriteRule  ^word/(.*)$  /$1  [R=301,L]

情况六
http://www.chinasoft.com/a.html 跳转到 http://www.daniusoft.com/b.html
非相同域名站点的跳转

写法如下:
RewriteRule  ^a.html   http://www.daniusoft.com/b.html [R=301,L]

情况七
http://www.chinasoft.com   跳转到 http://www.daniusoft.com
让 chinasoft.com 站点链接重新定向到 www.daniusoft.com

写法如下:
RewriteRule  (.*)$  http://www.daniusoft.com/$1  [R=301,L]
注意:这里 daniusoft.com 后面的 / 一定不能漏掉,如果漏掉的话,会出现如下错误:
chinasoft.com/a.html 跳转地址会是 daniusoft.coma.html  (该地址不存在)

情况八
http://www.chinasoft.com 下的所有文件   跳转到 http://www.daniusoft.com 首页
让 chinasoft.com 站点所有页面重新定向到 www.daniusoft.com 首页

写法如下:
RewriteRule  (.*)$  http://www.daniusoft.com  [R=301,L]

情况九
动态页面取值跳转
support.iskysoft.com/index.php?submod=order&method=retrieve 页面
跳到指定页面
support.iskysoft.com/contact-support/retrieve-registration-code.html

写法如下:
^/index.php /aaa/%{QUERY_STRING}? [R=301,L]
^/aaa/submod=order&method=retrieve /contact-support/retrieve-registration-code.html [R=301,L]

小技巧:
如果需要让一条跳转不生效,暂时又不想删除此条跳转,可能以后还会用到。
在此条跳转前面加一个”#”,表示注释掉,此跳转不生效。
例如:
RewriteEngine on
#RewriteRule  ^a.html  /b.html  [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
RewriteRule XXXXXXX XXXXXXX [R=301,L]
站点中 a.html 到 b.html 的跳转将不会生效。

生效原则:先后顺序

跳转遵从从上往下优先匹配原则。
一旦前面有覆盖后面跳转的跳转存在,以前面跳转为准
例 1:
RewriteEngine on
RewriteRule  ^a.html  /b.html  [R=301,L]
RewriteRule  ^a.html  /c.html   [R=301,L]
RewriteRule  ^a.html  /d.html  [R=301,L]
站点中 a.html 到 b.html 的跳转将会生效,其他两条不生效。
例 2:
RewriteEngine on
RewriteRule  ^word/ (.*)$  /sentence/$1  [R=301,L]
RewriteRule  ^word/a.html   /a.html   [R=301,L]
优先匹配  word/ 到 sentence / 的跳转。


由于历史原因,我们许多站点存在基于配置文件级的 301 跳转,这些跳转均优先于我们所编辑的 301jump 文件的跳转。

以下情况:
1、设置的跳转不生效。
2、跳转莫名奇妙的跳转到其他地址。
3、想取消一个跳转规则,怎么也找不到。

 
如果有大规模跳转需要设置(一次在 50 条以上), 把需要跳转的页面粘贴到新建文件 1,跳转到目标页面的粘贴到文件 2。

cat -n 1 >3
cat -n 2 >4
join -o 1.2,2.2 3 4 >5

完整站点示例:

root@server1 [/home/chinasoft0807/public_html]# more .htaccess
# 打开 zip 压缩
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/php
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^home\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /online/home.html [L]
</IfModule>

DirectoryIndex index.php index.html home.html
<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 1.180.17.231

RewriteOptions inherit


<IfModule include_module>
   Options +IncludesNoExec
</IfModule>

AddType text/html .shtml  .html  .htm
AddOutputFilter INCLUDES .shtml  .html  .htm

RewriteEngine on
# 强制跳转 https 和 www
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.io
RewriteRule ^(.*)$ https://www.chinasoft.io/$1 [R,L]

# 去掉 index.html
RewriteCond %{REQUEST_URI} ^(/index\.html)$ [NC]
RewriteRule ^(.*) / [R=301,L]

RewriteCond %{REQUEST_URI} !^(/index\.html)$ [NC]
RewriteCond %{REQUEST_URI} (/index\.html)$ [NC]
RewriteRule (.+)/index\.html /$1/ [R=301,L]

# /files 临时跳转 mm.edrasoft.com
Redirect 301 /files https://mm.chinasoft.com
# 404 调整默认首页
ErrorDocument 404 https://chinasoft.io/online/home.html

 

案例:

现象说明:
chinasoft.com下面有多语言站点 fr/jp/es/de 等

当访问 http://www.chinasoft.com/es/support.html 时,会自动跳转到主站的  http://www.chinasoft.com/support.html 页面
访问 https://www.chinasoft.com/es/support.html 没有问题,页面不会跳转


# 主站的rewrite规则配置
[/home/china007/public_html/es]# cat ../.htaccess
RewriteOptions inherit
RewriteEngine on

<IfModule include_module>
   Options +IncludesNoExec
</IfModule>

AddType text/html .shtml  .html  .htm
AddOutputFilter INCLUDES .shtml  .html  .htm

order deny,allow
deny from env=BadReferrer
<Files 403.shtml>
order allow,deny
allow from all
</Files>

DirectoryIndex en/index.html index.html index.php

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/php
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/html "access plus 1 weeks"
ExpiresByType text/php "access plus 1 weeks"
ExpiresByType text/css "access plus 1 days"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/plain "access plus 1 weeks"
ExpiresByType image/jpeg "access plus 1 weeks"
ExpiresByType image/gif "access plus 1 weeks"
ExpiresByType image/png "access plus 1 weeks"
ExpiresByType application/pdf "access plus 1 month"
ExpiresDefault "access plus 1 weeks"
</IfModule>

RewriteCond %{HTTP_HOST} ^50\.97\.132\.226
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule (.*) https://www.chinasoft.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.chinasoft.com  [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.com
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^(.*)$ https://www.chinasoft.com/$1 [R=301,L]

AddType application/edraw eddx

AddType application/x-newton-compatible-pkg pkg
AddType application/x-newton-compatible-dmg dmg
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^orderinfographics\.php$ "https\:\/\/www\.edrawsoft\.com\/orderinfographic\.php" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^download\/edrawmax\-cn\.exe$ "http\:\/\/www\.edrawsoft\.cn\/2download\/edrawmax\-cn\.exe" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^archives\/edrawmax\-cn\.dmg$ "http\:\/\/www\.edrawsoft\.cn\/2download\/edrawmax\-cn\.dmg" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^products\.html\&lang\=fr$ "https\:\/\/www\.edrawsoft\.com\/products\.html\?lang\=fr" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^products\.html\&lang\=jp$ "https\:\/\/www\.edrawsoft\.com\/products\.html\?lang\=jp" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^products\.html\&lang\=de$ "https\:\/\/www\.edrawsoft\.com\/products\.html\?lang\=de" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteRule ^shop2\/$ "http\:\/\/www\.edrawsoft\.cn\/shop\/" [R=301,L]

deny from 1.180.17.231
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^pages\/teamnotice\.html$ "https\:\/\/mm\.edrawsoft\.com\/pages\/teamnotice\.html" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^app\/index\.php$ "https\:\/\/www\.edrawsoft\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^edrawsoft\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.edrawsoft\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^en\/knowledge\/electricaldiagram\/$ "https\:\/\/www\.edrawsoft\.com\/en\/knowledge\/electrical\-diagram\/" [R=301,L]
RewriteRule ^en/(.*)$ https://www.chinasoft.com/$1 [R,L]

# 去掉index.html
RewriteCond %{REQUEST_URI} ^(/index\.html)$ [NC]
RewriteRule ^(.*) / [R=301,L]

RewriteCond %{REQUEST_URI} !^(/index\.html)$ [NC]
RewriteCond %{REQUEST_URI} (/index\.html)$ [NC]
RewriteRule (.+)/index\.html /$1/ [R=301,L]




# 多语言站点下的配置,添加针对 .htaccess文件并配置跳转规则
root@server1 [/home/china007/public_html/fr]# cat ../es/.htaccess 
RewriteOptions inherit

RewriteEngine on

<IfModule include_module>
   Options +IncludesNoExec
</IfModule>

AddType text/html .shtml  .html  .htm
AddOutputFilter INCLUDES .shtml  .html  .htm

# 将非https的站点强制跳转到https并且是多语言下
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.com
RewriteRule ^(.*)$ https://www.chinasoft.com/es/$1 [R,L]


# fr法语站的配置
root@server1 [/home/edra0604/public_html/fr]# more ../fr/.htaccess 
RewriteOptions inherit

RewriteEngine on

<IfModule include_module>
   Options +IncludesNoExec
</IfModule>

AddType text/html .shtml  .html  .htm
AddOutputFilter INCLUDES .shtml  .html  .htm


RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^chinasoft.com
RewriteRule ^(.*)$ https://www.chinasoft.com/fr/$1 [R,L]

eshell 中设置环境变量

eshell 中设置环境变量

eshell 是 Emacs 中内置的用 elisp 写成的命令行解释器。在 Emacs 使用 eshell 是一件非常舒服的事,比如使用 grep 的时候,emacs 会把结果重定向到一个新的分割窗口中去,避免了结果太多被刷屏。。。而且匹配到的文件名都带有链接,可以直接方便地用 emacs 打开。更有意思的是 eshell 随着 Emacs 一起跨平台了,很多功能在 Windows 下也能使用!不过之前一直困惑的一个问题是不知道 eshell 的环境变量在哪设置,自己一直是把环境变量写在~/.bashrc 中的,这样在 eshell 中无法读取。

1. 解决方案一

最初自己用笨办法,把要用到的命令创建链接到 /usr/bin/ 下面,能够解决一些问题,不过很麻烦,而且局限性太大。

2. 解决方案二

在 google 中搜索,相关的信息很少,有人提到过一个方法,是把环境变量写到.xsession 中去,不过自己尝试之后并不生效。

3. 解决方案三

把环境变量写到 /etc/profile 中去在整个系统范围内都有效,试了一下对 eshell 也是有效的。能够完美解决环境变量的问题。

4. 解决方案四

其实自己的想法是最好能把环境变量写到到 emacs 的配置文件中去。今天研究了下 elisp 的参考文档解决了这个问题。
以设置 java 的环境变量为例,在.emacs 中添加如下内容:
(setenv "JAVA_HOME" "/usr/lib/jvm/jdk1.6.0_35")
(setenv "PATH" (concat (getenv "PATH") ":" (getenv "JAVA_HOME") "/bin"))
其实就等同于:
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_35
export PATH=$PATH:$JAVA_HOME/bin
这个方法同样适用于 windows,不过要注意路径的写法不一样。

eshell中设置环境变量

eshell中设置环境变量

eshell是Emacs中内置的用elisp写成的命令行解释器。在Emacs使用eshell是一件非常舒服的事,比如使用grep的时候,emacs会把结果重定向到一个新的分割窗口中去,避免了结果太多被刷屏。。。而且匹配到的文件名都带有链接,可以直接方便地用emacs打开。更有意思的是eshell随着Emacs一起跨平台了,很多功能在Windows下也能使用!不过之前一直困惑的一个问题是不知道eshell的环境变量在哪设置,自己一直是把环境变量写在~/.bashrc中的,这样在eshell中无法读取。

1. 解决方案一

最初自己用笨办法,把要用到的命令创建链接到/usr/bin/下面,能够解决一些问题,不过很麻烦,而且局限性太大。

2. 解决方案二

在google中搜索,相关的信息很少,有人提到过一个方法,是把环境变量写到.xsession中去,不过自己尝试之后并不生效。

3. 解决方案三

把环境变量写到/etc/profile中去在整个系统范围内都有效,试了一下对eshell也是有效的。能够完美解决环境变量的问题。

4. 解决方案四

其实自己的想法是最好能把环境变量写到到emacs的配置文件中去。今天研究了下elisp的参考文档解决了这个问题。
以设置java的环境变量为例,在.emacs中添加如下内容:
(setenv "JAVA_HOME" "/usr/lib/jvm/jdk1.6.0_35")
(setenv "PATH" (concat (getenv "PATH") ":" (getenv "JAVA_HOME") "/bin"))
其实就等同于:
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_35
export PATH=$PATH:$JAVA_HOME/bin
这个方法同样适用于windows,不过要注意路径的写法不一样。

htaccess-如何比较环境变量-检查2个环境变量是否相同

htaccess-如何比较环境变量-检查2个环境变量是否相同

RewriteCond不允许在右侧使用变量。但是,存在一种变通方法,可以通过将两个变量组合为一个变量并使用否定条件声明相等性来实现这种比较。

RewriteCond %{ENV:HREFBASE}#%{ENV:PATHSTEM} !^([^#]+)#\1$
RewriteRule ^ %{REQUEST_SCHEME}://%{HTTP_HOST}/%{ENV:HREFBASE}%{REQUEST_URI} [R=302,L,NE]
  • 在这里,我们将两个变量与两者之间的已知定界符#组合在一起。
  • ^([^#]+)#匹配值直到#并捕获#1组中#之前的值。
  • \1$然后匹配组#1的后向引用
  • 请注意,!之前的^否定了此比较,从而有效地进行了以下比较:
    %{ENV:HREFBASE} != %{ENV:PATHSTEM}

关于在.htaccess中设置环境变量,然后在PHP中检索它php加入环境变量的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于apache 环境.htaccess 设置 301 跳转及常用.htaccess 技巧整理、eshell 中设置环境变量、eshell中设置环境变量、htaccess-如何比较环境变量-检查2个环境变量是否相同的相关信息,请在本站寻找。

本文标签: