编辑的.htaccess用PHP编辑、htaccess、PHP

由网友(莪纯属譃构)分享简介:我有一个域映射到一个文件夹中的.htaccess。I have a .htaccess that maps a domain to a folder.RewriteEngine OnRewriteBase /# redirect mapped domainReWriteCond %{HTTP_HOST} jos...

我有一个域映射到一个文件夹中的.htaccess。

I have a .htaccess that maps a domain to a folder.

RewriteEngine On
RewriteBase /

# redirect mapped domain
ReWriteCond %{HTTP_HOST} joshblease.uk.to
ReWriteCond %{REQUEST_URI} !gme-index/
ReWriteRule ^(.*)$ gme-index/$1 [L]

有什么办法来编辑/使用PHP添加额外的域名映射到该文件?

Is there any way to edit/add extra domain maps to the file using PHP?

简单地说,我想要得到的.htaccess文件的内容,并使用PHP脚本添加到他们。

Simply, I want to get the contents of the .htaccess file and add to them using a PHP script.

任何帮助AP preciated,约什。

Any help appreciated, Josh.

推荐答案

至于建议中的上述意见,最好是使用的 RewriteMap指令你这里的情况,而不是试图编辑从PHP $ C $的.htaccessÇ直接。下面是一个示例如何使用它:

As suggested in one of the comments above it is better to use RewriteMap for your case here rather than trying to edit .htaccess from PHP code directly. Here is a sample how to use it:

添加下面一行到你的httpd.conf文件:

Add following line to your httpd.conf file:

RewriteMap domainMap txt://path/to/domain-dir.txt

创建一个文本文件作为 /path/to/domain-dir.txt 是这样的:

Create a text file as /path/to/domain-dir.txt like this:

sub1 /subdir1
sub2 /foodir2
foo /bar

添加这些线在你的.htaccess文件:

php修改文件访问目录为 .htaccess 借github上韩国师傅的一个源码实例再次理解.htaccess的功效...

Add these line in your .htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*).domain.com$ [NC]
RewriteRule ^$ ${domainMap:%1} [L,R]

有效的所有句话的意思是让这些重定向的地方:

Effectively all this means is to have these redirects in place:

sub1.domain.com/ => sub1.domain.com/subdir1 sub2.domain.com/ => sub2.domain.com/foodir2 foo.domain.com/ => foo.domain.com/bar 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 code,而无需打开一个巨大的安全漏洞进行的.htaccess直接让PHP $ C $共同编辑。

Advantage: With this setup in place, you can edit or recreate the file /path/to/domain-dir.txt as much as you want from your php code without opening a huge security hole be allowing php code o edit .htaccess directly.

阅读全文

相关推荐

最新文章