RewriteEngine On
RewriteBase /
# redirect mapped domain
ReWriteCond %{HTTP_HOST} joshblease.uk.to
ReWriteCond %{REQUEST_URI} !gme-index/
ReWriteRule ^(.*)$gme-index/$1 [L]
简单地说,我想获取.htaccess文件的内容并使用PHP脚本添加到它们中.
解决方法:
正如上面的一条评论中所建议的那样,最好在这里使用RewriteMap而不是直接从PHP代码编辑.htaccess.以下是如何使用它的示例:
RewriteMap domainMap txt://path/to/domain-dir.txt
>将文本文件创建为/path/to/domain-dir.txt,如下所示:
sub1 /subdir1
sub2 /foodir2
foo /bar
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$[NC]
RewriteRule ^$${domainMap:%1} [L,R]
> sub1.domain.com/ => sub1.domain.com/subdir1
> sub2.domain.com/ => sub2.domain.com/foodir2
> foo.domain.com/ => foo.domain.com/bar
优点:有了这个设置,您可以根据需要编辑或重新创建文件/path/to/domain-dir.txt,而无需打开巨大的安全漏洞,允许PHP代码直接编辑.htaccess.